photopea / UZIP.js

Simple ZIPping library for Javascript
MIT License
187 stars 27 forks source link

split inflate/delate to two files #7

Closed jimmywarting closed 5 years ago

jimmywarting commented 5 years ago

for them who are only interested in one of them

photopea commented 5 years ago

I am a little worried to have many JS files here with redundant data. People would be confused by them.

But you could copy out inflate and minify it into 1 kB of JS code :)

jimmywarting commented 5 years ago

ok, got a question, i'm new to the hole inflate, deflate world how do you actually use this lib? i haven't tried pako yet either (thats where i found you)

Dose it work in a streaming/chunked fashion?


it would have been nice if it supported whatwg streams but i assume that would make it slower maybe? but at least it would make it as a cool new api


new Response('hello world').body
  .pipeThrought(new uzip.DeflateTransformer())
  .pipeThrought(new uzip.InflateTransformer())
  .pipeThrought(new TextDecoderStream())
  .pipeTo(new WritableStream({
    write (str) {
      console.log(str)
    }
  }))
photopea commented 5 years ago

The description is in README. UZIP uses typed arrays, both the input and the output is in JS memory (usually in RAM). The input is a sequence of bytes, and the output too.

jimmywarting commented 5 years ago

Figured this part out: a repeated 100 times

UZIP.deflate(new Uint8Array(100).fill(97)) // [120, 156, 75, 164, 3, 0, 0, 122, 71, 37, 229]

but how do you know how many bytes you should pass into the inflator?

i know pako had something like append and flush where as you don't?

edit meant

inflator.push(chunk1, false);
inflator.push(chunk2, false);
...
inflator.push(chunkN, true); // true -> last chunk
jimmywarting commented 5 years ago

hmm, maybe a inflator/delator isn't meant to compress/uncompress hole files? maybe the application should define blocks of sequences?

photopea commented 5 years ago

I am afraid I don't understand your problem. UZIP.deflate() converts any sequence of bytes into another sequence of bytes. UIZP.inflate() expects a valid sequence of bytes (data compressed by Deflate algrithm) and returns the original sequence of bytes.

Your code seems to take data in chunks. But you could concatenate all your chunks by yourself, and give them all to UZIP.inflate(), you would get the same result.