Coder Social home page Coder Social logo

rf00 / minizip-asm.js Goto Github PK

View Code? Open in Web Editor NEW
42.0 2.0 17.0 3.95 MB

Minizip in javascript. Work with password. Demo:

Home Page: https://rf00.github.io/minizip-asm.js/example/

License: Other

JavaScript 87.33% CSS 2.58% HTML 6.63% Shell 0.77% C++ 2.69%
extract compress zip password

minizip-asm.js's Introduction

minizip-asm.js

Build Status npm version

Minizip in javascript. Work with password. Demo: https://rf00.github.io/minizip-asm.js/example/

Features

  • Zip file
  • Extract file
  • Work with password

Installation

<script src="https://raw.githubusercontent.com/rf00/minizip-asm.js/master/lib/minizip-asm.min.js"></script>
npm install minizip-asm.js

var Minizip = require('minizip-asm.js');

Getting started

var fs = require("fs");

var text = new Buffer("Abc~~~");
var mz = new Minizip();

mz.append("haha/abc.txt", text, {password: "~~~"});
fs.writeFileSync("abc.zip", new Buffer(mz.zip()));

Usage

new Minizip(ArrayBuffer)

Constructor for making a new zip file or opening from existing one.

  • @ArrayBuffer {Buffer|Uint8Array} <optional> - It can be either Node.js Buffer read from zip file or Uint8Array in web browser.

  • @ Return an instance of Minizip.

mz.list(options)

List all files in Minizip with full filepath and have password or not.

  • @options <optional>

    • @encoding {"utf8"|"buffer"} <default="utf8"> - Since the filepath may not encode in utf8. It will be handy to have an ArrayBuffer to do detection on encoding.
  • @ Return an Array. Something like this:

    [{
      filepath: "haha/abc.txt",
      crypt: true // (type: boolean)
    }]

mz.extract(filepath, options)

Extract one file.

  • @filepath {String|Buffer|Uint8Array} - Full filepath to extract.

  • @options <optional>

    • @encoding {"utf8"|"buffer"} <default="buffer"> - File can return in text.

    • @password {String|Buffer|Uint8Array} <optional>

  • @ Return a Buffer.

mz.append(filepath, data, options)

Append one file.

  • @filepath {String|Buffer|Uint8Array} - Full filepath to extract.

  • @data {String|Buffer|Uint8Array} - File data.

  • @options <optional>

    • @password {String|Buffer|Uint8Array} <optional>

    • @compressLevel {Number} <default=5> - 0: Store only. 1: Compress faster. 9: Compress better.

  • @ Return nothing.

mz.zip()

Retrive zip file.

  • @ Return a Buffer.

Notice

  1. It is synchronize.
  2. Browser require >= IE11.

minizip-asm.js's People

Contributors

rf00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

minizip-asm.js's Issues

zip blob with password

Hi,
I'm working with Angular (typescript).
How I can create zip with password passing Blob object or string?
I don't want to use files on local paths.

Thanks

error with zipfile in unzGoToFirstFile

I have testing this library and created many files however at random a few of the zip files created throw up this error. I have not been able to find out what is specific to those files. I am including the code and the point where the error appears

                // read the buffer from file object
                const _filebuffer = await this._readBuffer(fileobj);
                // convert to uint8array
                const _arr = new Uint8Array(_filebuffer);
                // create new object using arr
                this._zip = new Minizip(_arr);
                // read list of zip content
                const _list = this._zip.list();

At the point of list() the library inconsistently throws up

Error: error with zipfile in unzGoToFirstFile
    at Minizip.list

Any help on why this happens will be greatly appreciated. Thanks

The zip size is more than than the actual size

Just testing out the implementation. My file is about 4K and when created a zip file using WinRar, its size becomes 1.7KB. However, with minizip, when I create the zip files, its size becomes 64KB, 16 times larger than the original file. Can you please check?

delete or update a file

Hello:

Is there a method to remove an existing file from the minizip object? or at least update it?

Thanks

Cannot read property 'TYPED_ARRAY_SUPPORT' of undefined at Object

I am using this library with Angular 8 when I install it with NPM and used it with var Minizip = require('minizip-asm.js'); its throwing error :

minizip-asm.min.js:18 Uncaught TypeError: Cannot read property 'TYPED_ARRAY_SUPPORT' of undefined
at Object. (minizip-asm.min.js:18)
at Object. (minizip-asm.min.js:18)
at r (minizip-asm.min.js:1)
at Object. (minizip-asm.min.js:17)
at r (minizip-asm.min.js:1)
at Object. (minizip-asm.min.js:14)
at Object. (minizip-asm.min.js:14)
at r (minizip-asm.min.js:1)
at minizip-asm.min.js:1
at minizip-asm.min.js:1

Unable to unzip a large file

// create file
import * as Minizip from 'minizip-asm.js'
import * as fs from 'fs'
var text = Buffer.from("content");
var mz = new Minizip();

mz.append("test.txt", text, {password: "psd"});
fs.writeFileSync("test.zip", Buffer.from(mz.zip()));

// extract file
import * as Minizip from 'minizip-asm.js'
import * as fs from 'fs'
var mz = new Minizip(Buffer.from(fs.readFileSync('test.zip'))); // fails here

var textBuffer = mz.extract('test.txt', { password: "psd"})
console.log(textBuffer.toString()); // "content"

Unable to Extract

Created Zip file using append.
But unable to extract the zip file.
It given 'Blank file' error.

Not minified minizip-asm.js

Do you have full minizip-asm.js with full source code on native JavaScript, not minified
minizip-asm.min.js.

I want to add unicode supporting for filenames, but minified file is very-very not readable.

Error: Can't get buffer length

When i try extract zip file which contains txt files
This error is displayed:
Error: Can't get buffer length

my code

` let mz=new minizip(Buffer.from(fs.readFileSync(filename)))

let buf=mz.extract('report.txt', { password: "abc"})
console.log(buf,'response')`

Inconsistent behaviour when trying to append() incorrect data types

So I needed to use this module, despite certain shortcomings, because it was the only one I found that supports passwords, and we're dealing with exporting personal information in our app. I note that when appending a file, you're supposed to provide a String, Buffer or Uint8Array as the data argument. However, when debugging, I noticed the following inconsistent behaviour when given edge-case or incorrect arguments:

  • With mz.append (with a password specified):
    • where data is given as one of undefined, null, 0 or 1 (numbers), false or true (booleans), or {} (empty object), it throws an exception right away (expected, those don't make sense as a file defined as an array of bytes)
    • where data is given as one of '' (empty string), or [] (empty array), doesn't throw an exception (expected, those make sense to me as representing an empty file)
    • where data is one of [{}, {}, {}] (array of empty objects), [{a:1,b:2},{a:11,b:22},{a:111,b:222}] (array of objects with consistent properties), [{a:1,b:2},{c:11,d:22},{e:111,f:222}] (array of objects with inconsistent properties), doesn't throw an exception (unexpected, they don't make sense as a file defined as an array of bytes)
  • Listed in the archive (when I try 7z l test.zip):
    • The mz.append attempts that didn't throw an exception, where that made sense to me, resulted in a 0-byte file added to the archive (expected)
    • The mz.append attempts that didn't throw an exception, where that didn't make sense to me, resulted in a 3-byte file added to the archive (matches the length of the array provided, but still doesn't make sense as a file)
    • The mz.append attempts that did throw an exception, did not result in a file being added to the archive (expected)
  • Extracting the archive (when I try 7z x test.zip):
    • The 0-byte files, that make sense to me, fail to extract with a bad CRC (ie the zip is corrupt) when a correct password was used. (This isn't the same error that appears when I actually try an incorrect password.) I still see actual 0-byte files extracted, despite the error.
    • Those same 0-byte files, extract successfully if no password was specified in the first place when adding them.
    • The 3-byte files, that don't make sense to me being added, extract without errors, and consist of 3 bytes of 0x00. (This is the same whether a correct password was specified, or when no password was specified in the first place.)

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.