@zip.js/zip.js 2.6.45 → 2.6.47

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/index.d.ts CHANGED
@@ -370,7 +370,7 @@ export class Uint8ArrayReader extends Reader<Uint8Array> { }
370
370
  *
371
371
  * @deprecated Use {@link SplitDataReader} instead.
372
372
  */
373
- export class SplitZipReader extends SplitDataReader
373
+ export class SplitZipReader extends SplitDataReader { }
374
374
 
375
375
  /**
376
376
  * Represents a `Reader` instance used to read data provided as an array of `Reader` instances (i.e. split zip files).
@@ -566,7 +566,7 @@ export class Data64URIWriter extends Writer<string> {
566
566
  *
567
567
  * @deprecated Use {@link SplitDataWriter} instead.
568
568
  */
569
- export class SplitZipWriter extends SplitDataWriter
569
+ export class SplitZipWriter extends SplitDataWriter { }
570
570
 
571
571
  /**
572
572
  * Represents a `Writer` instance used to retrieve the written data from a generator of `Writer` instances (i.e. split zip files).
@@ -854,7 +854,7 @@ export interface Entry {
854
854
  * @param options The options.
855
855
  * @returns A promise resolving to the type to data associated to `writer`.
856
856
  */
857
- getData?<Type>(writer: Writer<Type> | WritableWriter | WritableStream, options?: EntryGetDataOptions): Promise<Type>
857
+ getData?<Type>(writer: Writer<Type> | WritableWriter | WritableStream | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream, boolean>, options?: EntryGetDataOptions): Promise<Type>
858
858
  }
859
859
 
860
860
  /**
@@ -902,7 +902,7 @@ export class ZipWriter<Type> {
902
902
  * @param options The options.
903
903
  * @returns A promise resolving to an `Entry` instance.
904
904
  */
905
- add<ReaderType>(filename: string, reader?: Reader<ReaderType> | ReadableReader | ReadableStream, options?: ZipWriterAddDataOptions): Promise<Entry>
905
+ add<ReaderType>(filename: string, reader?: Reader<ReaderType> | ReadableReader | ReadableStream | Reader<unknown>[] | ReadableReader[] | ReadableStream[], options?: ZipWriterAddDataOptions): Promise<Entry>
906
906
  /**
907
907
  * Writes the entries directory, writes the global comment, and returns the content of the zip file
908
908
  *
package/lib/core/io.js CHANGED
@@ -46,7 +46,10 @@ const DEFAULT_CHUNK_SIZE = 64 * 1024;
46
46
 
47
47
  const PROPERTY_NAME_WRITABLE = "writable";
48
48
 
49
- import { UNDEFINED_VALUE } from "./constants.js";
49
+ import {
50
+ UNDEFINED_VALUE,
51
+ FUNCTION_TYPE
52
+ } from "./constants.js";
50
53
  import { getConfiguration } from "./configuration.js";
51
54
 
52
55
  class Stream {
@@ -646,6 +649,43 @@ async function initStream(stream, initSize) {
646
649
  }
647
650
  }
648
651
 
652
+ function initReader(reader) {
653
+ if (Array.isArray(reader)) {
654
+ reader = new SplitDataReader(reader);
655
+ }
656
+ if (reader instanceof ReadableStream) {
657
+ reader = {
658
+ readable: reader
659
+ };
660
+ }
661
+ return reader;
662
+ }
663
+
664
+ function initWriter(writer) {
665
+ if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE) {
666
+ writer = new SplitDataWriter(writer);
667
+ }
668
+ if (writer instanceof WritableStream) {
669
+ writer = {
670
+ writable: writer
671
+ };
672
+ }
673
+ const { writable } = writer;
674
+ if (writable.size === UNDEFINED_VALUE) {
675
+ writable.size = 0;
676
+ }
677
+ const splitZipFile = writer instanceof SplitDataWriter;
678
+ if (!splitZipFile) {
679
+ Object.assign(writer, {
680
+ diskNumber: 0,
681
+ diskOffset: 0,
682
+ availableSize: Infinity,
683
+ maxSize: Infinity
684
+ });
685
+ }
686
+ return writer;
687
+ }
688
+
649
689
  function readUint8Array(reader, offset, size, diskNumber) {
650
690
  return reader.readUint8Array(offset, size, diskNumber);
651
691
  }
@@ -655,6 +695,8 @@ const SplitZipWriter = SplitDataWriter;
655
695
 
656
696
  export {
657
697
  initStream,
698
+ initReader,
699
+ initWriter,
658
700
  readUint8Array,
659
701
  Reader,
660
702
  Writer,
@@ -26,7 +26,7 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- /* global BigInt, Response, ReadableStream, WritableStream */
29
+ /* global BigInt, Response */
30
30
  // deno-lint-ignore-file no-this-alias
31
31
 
32
32
  import {
@@ -71,9 +71,10 @@ import {
71
71
  } from "./codec-pool.js";
72
72
  import {
73
73
  initStream,
74
+ initReader,
75
+ initWriter,
74
76
  readUint8Array,
75
- BlobReader,
76
- SplitDataReader
77
+ BlobReader
77
78
  } from "./io.js";
78
79
  import { decodeText } from "./util/decode-text.js";
79
80
  import { Crc32 } from "./streams/codecs/crc32.js";
@@ -128,13 +129,8 @@ const ZIP64_EXTRACTION = {
128
129
  class ZipReader {
129
130
 
130
131
  constructor(reader, options = {}) {
131
- if (reader instanceof ReadableStream) {
132
- reader = {
133
- readable: reader
134
- };
135
- }
136
132
  Object.assign(this, {
137
- reader,
133
+ reader: initReader(reader),
138
134
  options,
139
135
  config: getConfiguration()
140
136
  });
@@ -146,11 +142,7 @@ class ZipReader {
146
142
  const { config } = zipReader;
147
143
  await initStream(reader);
148
144
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
149
- if (Array.isArray(reader)) {
150
- reader = new SplitDataReader(reader);
151
- } else {
152
- reader = new BlobReader(await new Response(reader.readable).blob());
153
- }
145
+ reader = new BlobReader(await new Response(reader.readable).blob());
154
146
  await initStream(reader);
155
147
  }
156
148
  if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
@@ -400,17 +392,10 @@ class ZipEntry {
400
392
  readable.diskNumberStart = diskNumberStart;
401
393
  readable.offset = dataOffset;
402
394
  const size = readable.size = compressedSize;
403
- if (writer instanceof WritableStream) {
404
- writer = {
405
- writable: writer
406
- };
407
- }
408
- const { writable } = writer;
409
- if (writable.size === UNDEFINED_VALUE) {
410
- writable.size = 0;
411
- }
412
395
  const signal = getOptionValue(zipEntry, options, "signal");
396
+ writer = initWriter(writer);
413
397
  await initStream(writer, uncompressedSize);
398
+ const { writable } = writer;
414
399
  const { onstart, onprogress, onend } = options;
415
400
  const workerOptions = {
416
401
  options: {
@@ -26,7 +26,7 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- /* global BigInt, ReadableStream, WritableStream */
29
+ /* global BigInt */
30
30
  // deno-lint-ignore-file no-this-alias
31
31
 
32
32
  import {
@@ -61,8 +61,7 @@ import {
61
61
  DIRECTORY_SIGNATURE,
62
62
  MIN_DATE,
63
63
  MAX_DATE,
64
- UNDEFINED_VALUE,
65
- FUNCTION_TYPE
64
+ UNDEFINED_VALUE
66
65
  } from "./constants.js";
67
66
  import {
68
67
  getConfiguration,
@@ -74,6 +73,8 @@ import {
74
73
  } from "./codec-pool.js";
75
74
  import {
76
75
  initStream,
76
+ initReader,
77
+ initWriter,
77
78
  BlobWriter,
78
79
  SplitDataWriter
79
80
  } from "./io.js";
@@ -108,27 +109,10 @@ const pendingEntries = [];
108
109
  class ZipWriter {
109
110
 
110
111
  constructor(writer, options = {}) {
111
- if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE) {
112
- writer = new SplitDataWriter(writer);
113
- }
114
- if (writer instanceof WritableStream) {
115
- writer = { writable: writer };
116
- }
117
- if (writer.writable.size === UNDEFINED_VALUE) {
118
- writer.writable.size = 0;
119
- }
120
- const splitZipFile = writer instanceof SplitDataWriter;
121
- if (!splitZipFile) {
122
- Object.assign(writer, {
123
- diskNumber: 0,
124
- diskOffset: 0,
125
- availableSize: Infinity,
126
- maxSize: Infinity
127
- });
128
- }
112
+ writer = initWriter(writer);
129
113
  Object.assign(this, {
130
114
  writer,
131
- addSplitZipSignature: splitZipFile,
115
+ addSplitZipSignature: writer instanceof SplitDataWriter,
132
116
  options,
133
117
  config: getConfiguration(),
134
118
  files: new Map(),
@@ -273,11 +257,7 @@ async function addFile(zipWriter, name, reader, options) {
273
257
  let maximumEntrySize = 0;
274
258
  let uncompressedSize = 0;
275
259
  if (reader) {
276
- if (reader instanceof ReadableStream) {
277
- reader = {
278
- readable: reader
279
- };
280
- }
260
+ reader = initReader(reader);
281
261
  await initStream(reader);
282
262
  if (reader.size === UNDEFINED_VALUE) {
283
263
  dataDescriptor = true;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
4
4
  "author": "Gildas Lormeau",
5
5
  "license": "BSD-3-Clause",
6
- "version": "2.6.45",
6
+ "version": "2.6.47",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",
@@ -24,7 +24,7 @@ async function test() {
24
24
  new zip.TextReader(TEXT_CONTENT),
25
25
  new zip.BlobReader(BLOB_CONTENT)
26
26
  ];
27
- await zipWriter.add("loremx2.txt", new zip.SplitDataReader(readers));
27
+ await zipWriter.add("loremx2.txt", readers);
28
28
  const blob = await zipWriter.close();
29
29
  const zipReader = new zip.ZipReader(new zip.BlobReader(blob));
30
30
  const firstEntry = (await zipReader.getEntries()).shift();