Skip to content

Repository files navigation

archive

Build Status

Overview

A Dart library to encode and decode various archive and compression formats.

The library has no reliance on dart:io, so it can be used for both server and web applications.

The archive library currently supports the following decoders:

  • Zip (Archive)
  • Tar (Archive)
  • ZLib [Inflate decompression]
  • GZip [Inflate decompression]
  • BZip2 [decompression]

And the following encoders:

  • Zip (Archive)
  • Tar (Archive)
  • ZLib [Deflate compression]
  • GZip [Deflate compression]
  • BZip2 [compression]

Sample

Extract the contents of a Zip file, and encode the contents as a BZip2 compressed Tar file:

import'dart:io'as Io;
import'package:archive/archive.dart';
voidmain() {
// Read the Zip file from disk.List<int> bytes =newIo.File('test.zip').readAsBytesSync();
// Decode the Zip fileArchive archive =newZipDecoder().decodeBytes(bytes);
// Extract the contents of the Zip archive to disk.for (ArchiveFile file in archive) {
String filename = file.name;
List<int> data = file.content;
newIo.File('out/'+ filename)
..createSync(recursive:true)
..writeAsBytesSync(data);
}
// Encode the archive as a BZip2 compressed Tar file.List<int> tar_data =newTarEncoder().encode(archive);
List<int> tar_bz2 =newBZip2Encoder().encode(tar_data);
// Write the compressed tar file to disk.Io.File fp =newIo.File(filename +'.tbz');
fp.writeAsBytesSync(tar_bz2);
}

About

Dart library to encode and decode various archive and compression formats, such as Zip and Tar.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages