Crates.io | wasm-zip-stream |
lib.rs | wasm-zip-stream |
version | 0.1.0 |
source | src |
created_at | 2024-11-09 14:24:45.172049 |
updated_at | 2024-11-09 14:24:45.172049 |
description | A stream style zip compressing tool targeting wasm |
homepage | https://github.com/LittleSaya/wasm-zip-stream |
repository | https://github.com/LittleSaya/wasm-zip-stream |
max_upload_size | |
id | 1442118 |
size | 82,501 |
A stream style zip compressor running in browser.
wasm-pack build --release --target web
This library allows users to compress a lot of files into a very big zip file and download it locally. An another library, StreamSaver.js
,
is required as the runtime dependency of this library, it is because StreamSaver.js
can produce the required WritableStreamDefaultWriter
that will be used when creating the file writer.
StreamSaver.js
can be found on https://github.com/jimmywarting/StreamSaver.js
.
The presence of StreamSaver.js
also means that you will need a HTTPS environment.
The exported function initialize_context()
will return a Handles
object, which has some methods you can use:
scan
accepts an array of FileSystemEntry
s, which you can get from the dataTransfer
property in DargEvent
.compress
accepts a file name and a compression level, this method will create a writer, compress scanned files into a zip file stream,
and use that writer to write the stream to user's file system.register_scan_progress
accepts a callback like (number_of_scanned_entries: number) => {}
for each encountered file.register_compress_progress
accepts a callback like (number_of_compressed_files: number, number_of_all_files: number) => {}
.register_average_speed
accepts a callback like (total_bytes_written: number, total_time_elapsed: number) => {}
.register_current_speed
accepts a callback like (delta_bytes_written: number, delta_time_elapsed: number) => {}
.register_current_file
accepts a callback like (path: string) => {}
.For detailed description please refer to docs.rs.
A working example could be found here, you can inspect files using devtool or find files under the example
folder in github repo.