@zip.js/zip.js 2.5.26 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,3 +2,65 @@ zip.js is an open-source library (BSD-3-Clause license) for zipping and unzippin
2
2
 
3
3
  See here for more info:
4
4
  https://gildas-lormeau.github.io/zip.js/
5
+
6
+ ```js
7
+ // Hello world with zip.js (and Streams)
8
+
9
+ import { ZipWriter, ZipReader, BlobReader } from "https://deno.land/x/zipjs/index.js";
10
+
11
+ // ----
12
+ // Write the zip file
13
+ // ----
14
+
15
+ // Creates a TransformStream object where the zip content will be written.
16
+ const zipStream = new TransformStream();
17
+ // Creates a Promise object resolved to the zip content returned as a Blob object.
18
+ const zipBlobPromise = new Response(zipStream.readable).blob();
19
+ // Creates a ReadableStream object containing the text of the entry to add in the zip.
20
+ const helloWorldReadable = new Blob(["Hello world!"], { type: "text/plain" }).stream();
21
+
22
+
23
+ // Creates a ZipWriter object writing data via zipStream, adds the file "hello.txt" containing
24
+ // the text "Hello world!" via helloWorldReadable in the zip, and closes the writer.
25
+ const zipWriter = new ZipWriter(zipStream);
26
+ await zipWriter.add("hello.txt", { readable: helloWorldReadable });
27
+ await zipWriter.close();
28
+
29
+
30
+ // Retrieves the Blob object containing the zip content.
31
+ const zipBlob = await zipBlobPromise;
32
+
33
+ // Uncomment the following code to download the zip file (in a browser)
34
+ //
35
+ // const anchorElement = document.createElement("a");
36
+ // anchorElement.href = URL.createObjectURL(zipBlob);
37
+ // anchorElement.download = "hello.zip";
38
+ // anchorElement.click();
39
+ //
40
+
41
+
42
+ // ----
43
+ // Read the zip file
44
+ // ----
45
+
46
+ // Creates a TransformStream object where the content of the first entry in the zip will be written.
47
+ const contentStream = new TransformStream();
48
+ // Creates a Promise object resolved to the first entry content returned as text.
49
+ const contentTextPromise = new Response(contentStream.readable).text();
50
+
51
+
52
+ // Reads zipBlob via a BlobReader object, retrieves metadata (name, dates, etc.) of the first entry,
53
+ // retrieves its content via contentStream, and closes the reader.
54
+ // Note: it is *not* possible to use a ReadableStream object to read a zip because random access
55
+ // to data is required to fetch entries reliably and efficiently.
56
+ const zipReader = new ZipReader(new BlobReader(zipBlob));
57
+ const firstEntry = (await zipReader.getEntries()).shift();
58
+ await firstEntry.getData(contentStream);
59
+ await zipReader.close();
60
+
61
+
62
+ // Displays "Hello world!".
63
+ const contentText = await contentTextPromise;
64
+ console.log(contentText);
65
+ ```
66
+ See here for more examples: https://github.com/gildas-lormeau/zip.js/tree/master/tests/all
@@ -3,7 +3,7 @@
3
3
  /* global Deno, fetch, URL, TextEncoderStream */
4
4
 
5
5
  import { parse as parseArgs } from "https://deno.land/std@0.147.0/flags/mod.ts";
6
- import { fromFileUrl, normalize as normalizePath, resolve as resolvePath, extname } from "https://deno.land/std@0.147.0/path/mod.ts";
6
+ import { normalize as normalizePath, resolve as resolvePath, extname } from "https://deno.land/std@0.147.0/path/mod.ts";
7
7
  import { configure, ZipWriter, terminateWorkers } from "../index.js";
8
8
 
9
9
  const args = parseArgs(Deno.args);
@@ -99,8 +99,6 @@ async function getFileInfo(file, options) {
99
99
  if (!extname(name)) {
100
100
  name += ".html";
101
101
  }
102
- } else if (file.startsWith("file:")) {
103
- name = fromFileUrl(file);
104
102
  } else {
105
103
  name = file;
106
104
  resolvedName = resolvePath(name);
@@ -7017,7 +7017,6 @@
7017
7017
  const MESSAGE_PULL = "pull";
7018
7018
  const MESSAGE_DATA = "data";
7019
7019
  const MESSAGE_CLOSE = "close";
7020
- const ERR_ABORT = "AbortError";
7021
7020
 
7022
7021
  class Codec {
7023
7022
 
@@ -7285,7 +7284,7 @@
7285
7284
  let indexWorker = 0;
7286
7285
 
7287
7286
  async function runWorker(stream, workerOptions) {
7288
- const { options, config, streamOptions } = workerOptions;
7287
+ const { options, config } = workerOptions;
7289
7288
  const streamCopy = !options.compressed && !options.signed && !options.encrypted;
7290
7289
  const { useWebWorkers, useCompressionStream, codecType } = options;
7291
7290
  const { workerScripts } = config;
@@ -7307,16 +7306,7 @@
7307
7306
  worker = await new Promise(resolve => pendingRequests.push({ resolve, stream, workerOptions }));
7308
7307
  }
7309
7308
  }
7310
- try {
7311
- return await worker.run();
7312
- } catch (error) {
7313
- const { signal } = streamOptions;
7314
- if (signal && signal.aborted && (signal.reason == error || error.name == ERR_ABORT)) {
7315
- throw new Error(ERR_ABORT);
7316
- } else {
7317
- throw error;
7318
- }
7319
- }
7309
+ return worker.run();
7320
7310
 
7321
7311
  function onTaskFinished(workerData) {
7322
7312
  if (pendingRequests.length) {
@@ -7463,7 +7453,6 @@
7463
7453
 
7464
7454
  const ERR_HTTP_STATUS = "HTTP error ";
7465
7455
  const ERR_HTTP_RANGE = "HTTP Range not supported";
7466
- const ERR_NOT_SEEKABLE_READER = "Reader is not seekable";
7467
7456
 
7468
7457
  const CONTENT_TYPE_TEXT_PLAIN = "text/plain";
7469
7458
  const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
@@ -7698,32 +7687,6 @@
7698
7687
  blobWriter.arrayBuffers = [];
7699
7688
  }
7700
7689
 
7701
- class ReadableStreamReader extends Stream {
7702
-
7703
- constructor(readable) {
7704
- super();
7705
- if (!readable) {
7706
- this.readable = new ReadableStream({});
7707
- }
7708
- }
7709
- }
7710
-
7711
- class WritableStreamWriter extends Writer {
7712
-
7713
- constructor(writable, { preventClose } = {}) {
7714
- super();
7715
- this.preventClose = preventClose;
7716
- if (!writable) {
7717
- writable = new WritableStream({});
7718
- }
7719
- Object.defineProperty(this, "writable", {
7720
- get() {
7721
- return writable;
7722
- }
7723
- });
7724
- }
7725
- }
7726
-
7727
7690
  class FetchReader extends Reader {
7728
7691
 
7729
7692
  constructor(url, options) {
@@ -10096,7 +10059,6 @@
10096
10059
  exports.BlobWriter = BlobWriter;
10097
10060
  exports.Data64URIReader = Data64URIReader;
10098
10061
  exports.Data64URIWriter = Data64URIWriter;
10099
- exports.ERR_ABORT = ERR_ABORT;
10100
10062
  exports.ERR_BAD_FORMAT = ERR_BAD_FORMAT;
10101
10063
  exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
10102
10064
  exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
@@ -10116,19 +10078,16 @@
10116
10078
  exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
10117
10079
  exports.ERR_INVALID_VERSION = ERR_INVALID_VERSION;
10118
10080
  exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
10119
- exports.ERR_NOT_SEEKABLE_READER = ERR_NOT_SEEKABLE_READER;
10120
10081
  exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
10121
10082
  exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
10122
10083
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
10123
10084
  exports.HttpRangeReader = HttpRangeReader;
10124
10085
  exports.HttpReader = HttpReader;
10125
- exports.ReadableStreamReader = ReadableStreamReader;
10126
10086
  exports.Reader = Reader;
10127
10087
  exports.TextReader = TextReader;
10128
10088
  exports.TextWriter = TextWriter;
10129
10089
  exports.Uint8ArrayReader = Uint8ArrayReader;
10130
10090
  exports.Uint8ArrayWriter = Uint8ArrayWriter;
10131
- exports.WritableStreamWriter = WritableStreamWriter;
10132
10091
  exports.Writer = Writer;
10133
10092
  exports.ZipReader = ZipReader;
10134
10093
  exports.ZipWriter = ZipWriter;