• Stars
    star
    5
  • Rank 2,861,937 (Top 57 %)
  • Language
    Ada
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Ada 2012 library for document container files

Alire dcf Alire zipdcf License GitHub release IRC Gitter chat

dcf-ada

An Ada 2012 library for document container files, a Zip-based archive files with 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 the Zip-Ada library, with extensive modifications:

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

  • Reformatted code to Ada default style guide

  • Removed obsolescent features and implementation-defined extensions

  • All packages except one that uses Ada.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 queried or 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 calling DCF.Zip.Load (Info, Archive_Stream). While the Info and Archive_Stream objects are in scope, the files can 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 the archive and then extracting each of them:

procedure Visit_File (File : DCF.Zip.Archived_File) is
begin
   Ada.Text_IO.Put_Line ("Visiting " & File.Name);
end Visit_File;

procedure Visit_All_Files is new DCF.Zip.Traverse (Visit_File);
procedure Visit_One_File  is new DCF.Zip.Traverse_One_File (Visit_File);

Call Visit_All_Files (Info) to visit all files. To extract a single file, call Visit_One_File (Info, "my-file.txt") instead.

Querying an archived file

A File object of type Archived_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" algorithm and 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 files cannot be decrypted and extracted

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

Extracting an archived file

While visiting an archived file, the file can be extracted using a Stream_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 a Stream_Element_Array, use DCF.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, set Verify_Integrity to True and use null in the discriminant of Stream_Writer.

Note that you should verify that File.Name is a valid path and sanitize it 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 and make

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 the contributing guidelines before opening issues or pull requests.

License

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

SPDX-License-Identifier: MIT

More Repositories

1

orka

The OpenGL 4.6 Rendering Kernel in Ada 2012
Ada
52
star
2

OpenRTI

Mirror of OpenRTI on SourceForge. Do not create PR's. Instead send patches or git pull commands to the mailing list on SF.
C++
51
star
3

json-ada

An Ada 2012 library for parsing JSON
Ada
35
star
4

inotify-ada

An Ada 2012 library for monitoring filesystem events using Linux' inotify API
Ada
8
star
5

emojis

An Ada 2012 library to replace names between colons with emojis
Ada
7
star
6

xoshiro

Ada/SPARK port of the xoshiro128++ and xoshiro256++ pseudo-random number generators
Ada
7
star
7

wayland-ada

Ada 2012 bindings for Wayland
Ada
6
star
8

orka-demo

Demo project using Orka 3D engine
Ada
4
star
9

evdev-ada

An Ada 2012 library to read input events and use force-feedback using Linux' evdev API
Ada
4
star
10

canberra-ada

Ada 2012 bindings for libcanberra
Ada
4
star
11

awt

Ada Window Toolkit, a library for managing input devices and windows that can display 3D graphics
3
star
12

weechat-ada

Ada 2012 library for WeeChat plug-ins
Ada
3
star
13

vim-ada

Modified Vim script for Ada 2012
Vim Script
2
star
14

weechat-emoji

A WeeChat plug-in written in Ada 2012 🥰 that displays emoji 🥳
Ada
2
star
15

spoon

An Ada 2012 library for posix_spawn() to spawn processes without a fork().
Ada
2
star
16

opus-ada

Ada 2012 bindings for the Opus audio codec.
Ada
2
star
17

xdg-base-dir

Ada 2012 library implementing the XDG Base Directory Specification
Ada
1
star
18

goblin-terminal

A mutated clone of GNOME Terminal
Python
1
star
19

weechat-canberra

A WeeChat plug-in written in Ada 2012 that plays sounds using libcanberra
Ada
1
star