翻译:
一个用于读取和写作ZIP档案的图书馆,在有条件的地方使用本地平台API进行压缩.
-
使用本地平台实施zlib/deflate(几乎无所不在), 只有在其他失败时才回到联署机构.
-
QQ在内存中保持拉链压缩,而不是在负载上扩展所有.
-
校对:Soup.
-
满打字为方便.
安装
npm install @borgar/zip
使用量
import { ZipArchive } from '@borgar/zip';
// Read an existing archive
const zip = new ZipArchive(arrayBuffer);
const text = await zip.readText('hello.txt'); // "hello world\n"
const data = await zip.read('image.png'); // ArrayBuffer([ 89 50 4E 47 0D 0A 1A 0A... ])
// Create a new archive
const zip = new ZipArchive();
await zip.write('hello.txt', text);
await zip.write('data.bin', data);
// Or write without awaiting each call. Entries are added in call order.
zip.write('a.txt', 'a');
zip.write('b.txt', 'b');
await zip.done(); // waits for all pending writes
const output = zip.toArrayBuffer();
// Trigger a browser download
const zipBlob = new Blob([ output ]);
const urlObject = URL.createObjectURL(zipBlob);
const a = document.createElement('a');
a.href = urlObject;
a.download = 'MyFilename.zip';
a.click();
URL.revokeObjectURL(urlObject);
API 密码
API 完全记录在 API.md (英语)。 。 。 .