Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

An Ada 2012 library for document container files

License

NotificationsYou must be signed in to change notification settings

onox/dcf-ada

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alire dcfAlire zipdcfLicenseGitHub releaseIRCGitter chat

dcf-ada

An Ada 2012 library for document container files, a Zip-based archive fileswith some limitations:

  • Only the "store" (uncompressed) and "deflate" (RFC 1951)compression methods can be used

  • Archives cannot be encrypted or contain digital signatures

  • Archives cannot be split into multiple files

This library is based on theZip-Ada library, with extensivemodifications:

  • Binary and Windows-specific files have been removed withThe BFG Repo Cleaner

  • Reformatted code to Ada default style guide

  • Removed obsolescent features and implementation-defined extensions

  • All packages except one that usesAda.Calendar are preelaborated

  • Removed unneeded features

  • Removed lots of duplicated code and simplified the API, reducing SLOC from 12k to 4.5k

Usage

Before the archived files in a document container file can be queriedor extracted, the archive first needs to be opened and loaded:

Archive_Stream :aliased DCF.Streams.File_Zipstream := DCF.Streams.Open (Archive_Name);Info : DCF.Zip.Zip_Info;

Then load the archive by callingDCF.Zip.Load (Info, Archive_Stream).While theInfo andArchive_Stream objects are in scope, the filescan be visited in order to extract them.

Visiting archived files in a document container file

Files can be extracted by visiting over all the archived files in thearchive and then extracting each of them:

procedureVisit_File (File : DCF.Zip.Archived_File)isbegin   Ada.Text_IO.Put_Line ("Visiting" & File.Name);endVisit_File;procedureVisit_All_Filesisnew DCF.Zip.Traverse (Visit_File);procedureVisit_One_Fileisnew DCF.Zip.Traverse_One_File (Visit_File);

CallVisit_All_Files (Info) to visit all files. To extract a singlefile, callVisit_One_File (Info, "my-file.txt") instead.

Querying an archived file

AFile object of typeArchived_File can be queried:

  • Name returns the name (path) of the file

  • Compressed_Size gives the compressed size

  • Uncompressed_Size gives the uncompressed size

  • Date_Time returns the modification date and time

  • Compressed returns True if compressed with the "deflate" algorithmand False if stored uncompressed

  • Encrypted returns True if the file is encrypted and False otherwise.Note that encryption is prohibited and not supported, thus these filescannot be decrypted and extracted

  • CRC_32 returns the CRC code. This number can be printed withDCF.Zip.CRC.Image

Extracting an archived file

While visiting an archived file, the file can be extracted using aStream_Writer object. First create the file and then write to it:

declare   File_Stream   :aliased DCF.Streams.File_Zipstream := DCF.Streams.Create (File.Name);   Stream_Writer : DCF.Unzip.Streams.Stream_Writer (File_Stream'Access);begin   DCF.Unzip.Streams.Extract     (Destination      => Stream_Writer,      Archive_Info     => Info,      File             => File,      Verify_Integrity => False);end;

If you want to extract to aStream_Element_Array, useDCF.Streams.Array_Zipstream:

declare   Byte_Stream   :aliased DCF.Streams.Array_Zipstream (My_Element_Array'Access);   Stream_Writer : DCF.Unzip.Streams.Stream_Writer (Byte_Stream'Access);begin

If you want to verify the integrity of the file without extracting it, setVerify_Integrity toTrue and usenull in the discriminant ofStream_Writer.

Note that you should verify thatFile.Name is a valid path and sanitizeit before attempting to create and write to the file.

Dependencies

In order to build the library, you need to have:

  • An Ada 2012 compiler

  • Alire andmake

Using the library

Use the library in your crates as follows:

alr with dcf

Installing the tools

Some tools to compress or decompress document container files can be build with:

$ make$ make PREFIX=~/.local install

Thanks

Much thanks to @zertovitch for the Zip-Ada project.

Contributing

Please read thecontributing guidelines before openingissues or pull requests.

License

This library is distributed under the terms of theMIT License.The first line of each Ada file should contain an SPDX license identifiertag that refers to this license:

SPDX-License-Identifier: MIT

About

An Ada 2012 library for document container files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp