GithubHelp home page GithubHelp logo

bladeofgod / archive Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brendan-duncan/archive

0.0 0.0 0.0 2.97 MB

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

License: MIT License

Dart 99.96% HTML 0.04%

archive's Introduction

archive

Dart CI pub package

Overview

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

The archive library currently supports the following decoders:

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

And the following encoders:

  • Zip (Archive)
  • Tar (Archive)
  • ZLib [Deflate compression]
  • GZip [Deflate compression]
  • BZip2 [compression]
  • XZ [uncompressed data only]

Usage

There are two versions of the Archive library:

package:archive/archive.dart

  • Can be used for web applications since it has no dependency on 'dart:io'.

package:archive/archive_io.dart

  • For Flutter and server applications, with direct file access to reduce memory usage. All classes and functions of archive.dart are included in archive_io.dart.

archive_io

The archive_io library contains classes and functions for accessing the file system. These classes and functions can significantly reduce memory usage for decoding archives directly to disk.

Using InputFileStream and OutputFileStream to reduce memory usage:

import 'package:archive/archive_io.dart';
// ...
  // Use an InputFileStream to access the zip file without storing it in memory.
  final inputStream = InputFileStream('test.zip');
  // Decode the zip from the InputFileStream. The archive will have the contents of the
  // zip, without having stored the data in memory. 
  final archive = ZipDecoder().decodeBuffer(inputStream);
  // For all of the entries in the archive
  for (var file in archive.files) {
    // If it's a file and not a directory 
    if (file.isFile) {
      // Write the file content to a directory called 'out'.
      // In practice, you should make sure file.name doesn't include '..' paths
      // that would put it outside of the extraction directory.
      // An OutputFileStream will write the data to disk.
      final outputStream = OutputFileStream('out/${file.name}');
      // The writeContent method will decompress the file content directly to disk without
      // storing the decompressed data in memory. 
      file.writeContent(outputStream);
      // Make sure to close the output stream so the File is closed.
      outputStream.close();
    }
  }

extractFileToDisk

extractFileToDisk is a convenience function to extract the contents of an archive file directory to an output directory. The type of archive it is will be determined by the file extension.

import 'package:archive/archive_io.dart';
// ...
extractFileToDisk('test.zip', 'out');

extractArchiveToDisk

extractArchiveToDisk is a convenience function to write the contents of an Archive to an output directory.

import 'package:archive/archive_io.dart';
// ...
// Use an InputFileStream to access the zip file without storing it in memory.
final inputStream = InputFileStream('test.zip');
// Decode the zip from the InputFileStream. The archive will have the contents of the
// zip, without having stored the data in memory. 
final archive = ZipDecoder().decodeBuffer(inputStream);
extractArchiveToDisk(archive, 'out');

archive's People

Contributors

brendan-duncan avatar androidseb avatar devoncarew avatar kevmoo avatar grundid avatar alestiago avatar robert-ancell avatar jporsay avatar therealpaco avatar brendan-duncan-g avatar bostrot avatar fjulian-epack avatar domesticmouse avatar srawlins avatar nex3 avatar magicalmouse39 avatar hrmoh avatar blaugold avatar davidmorgan avatar brianquinlan avatar matanlurey avatar mosuem avatar nttat-chin-shou avatar sigurdm avatar simolus3 avatar skythomp16 avatar sohomdatta1 avatar thelastgimbus avatar tvolkert avatar wilkomanger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.