@donezone/cli 0.1.44 → 0.1.46

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.
Files changed (2) hide show
  1. package/dist/index.js +178 -60
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -22221,6 +22221,9 @@ class AbstractTokenizer {
22221
22221
  return token.get(this.numBuffer, 0);
22222
22222
  }
22223
22223
  async ignore(length) {
22224
+ if (length < 0) {
22225
+ throw new RangeError("ignore length must be \u2265 0 bytes");
22226
+ }
22224
22227
  if (this.fileInfo.size !== undefined) {
22225
22228
  const bytesLeft = this.fileInfo.size - this.position;
22226
22229
  if (length > bytesLeft) {
@@ -22319,6 +22322,9 @@ var init_ReadStreamTokenizer = __esm(() => {
22319
22322
  return bytesRead;
22320
22323
  }
22321
22324
  async ignore(length) {
22325
+ if (length < 0) {
22326
+ throw new RangeError("ignore length must be \u2265 0 bytes");
22327
+ }
22322
22328
  const bufSize = Math.min(maxBufferSize, length);
22323
22329
  const buf = new Uint8Array(bufSize);
22324
22330
  let totBytesRead = 0;
@@ -24248,6 +24254,23 @@ var init_supported = __esm(() => {
24248
24254
  });
24249
24255
 
24250
24256
  // ../../node_modules/file-type/core.js
24257
+ function patchWebByobTokenizerClose(tokenizer) {
24258
+ const streamReader = tokenizer?.streamReader;
24259
+ if (streamReader?.constructor?.name !== "WebStreamByobReader") {
24260
+ return tokenizer;
24261
+ }
24262
+ const { reader } = streamReader;
24263
+ const cancelAndRelease = async () => {
24264
+ await reader.cancel();
24265
+ reader.releaseLock();
24266
+ };
24267
+ streamReader.close = cancelAndRelease;
24268
+ streamReader.abort = async () => {
24269
+ streamReader.interrupted = true;
24270
+ await cancelAndRelease();
24271
+ };
24272
+ return tokenizer;
24273
+ }
24251
24274
  function getSafeBound(value, maximum, reason) {
24252
24275
  if (!Number.isFinite(value) || value < 0 || value > maximum) {
24253
24276
  throw new ParserHardLimitError(`${reason} has invalid size ${value} (maximum ${maximum} bytes)`);
@@ -24589,6 +24612,39 @@ function normalizeSampleSize(sampleSize) {
24589
24612
  }
24590
24613
  return Math.max(1, Math.trunc(sampleSize));
24591
24614
  }
24615
+ function readByobReaderWithSignal(reader, buffer, signal) {
24616
+ if (signal === undefined) {
24617
+ return reader.read(buffer);
24618
+ }
24619
+ signal.throwIfAborted();
24620
+ return new Promise((resolve3, reject) => {
24621
+ const cleanup = () => {
24622
+ signal.removeEventListener("abort", onAbort);
24623
+ };
24624
+ const onAbort = () => {
24625
+ const abortReason = signal.reason;
24626
+ cleanup();
24627
+ (async () => {
24628
+ try {
24629
+ await reader.cancel(abortReason);
24630
+ } catch {
24631
+ }
24632
+ })();
24633
+ reject(abortReason);
24634
+ };
24635
+ signal.addEventListener("abort", onAbort, { once: true });
24636
+ (async () => {
24637
+ try {
24638
+ const result = await reader.read(buffer);
24639
+ cleanup();
24640
+ resolve3(result);
24641
+ } catch (error) {
24642
+ cleanup();
24643
+ reject(error);
24644
+ }
24645
+ })();
24646
+ });
24647
+ }
24592
24648
  function normalizeMpegOffsetTolerance(mpegOffsetTolerance) {
24593
24649
  if (!Number.isFinite(mpegOffsetTolerance)) {
24594
24650
  return 0;
@@ -24739,7 +24795,10 @@ class FileTypeParser {
24739
24795
  ...this.tokenizerOptions
24740
24796
  };
24741
24797
  }
24742
- async fromTokenizer(tokenizer, detectionReentryCount = 0) {
24798
+ createTokenizerFromWebStream(stream) {
24799
+ return patchWebByobTokenizerClose(fromWebStream(stream, this.getTokenizerOptions()));
24800
+ }
24801
+ async parseTokenizer(tokenizer, detectionReentryCount = 0) {
24743
24802
  this.detectionReentryCount = detectionReentryCount;
24744
24803
  const initialPosition = tokenizer.position;
24745
24804
  for (const detector of this.detectors) {
@@ -24763,6 +24822,13 @@ class FileTypeParser {
24763
24822
  }
24764
24823
  }
24765
24824
  }
24825
+ async fromTokenizer(tokenizer) {
24826
+ try {
24827
+ return await this.parseTokenizer(tokenizer);
24828
+ } finally {
24829
+ await tokenizer.close();
24830
+ }
24831
+ }
24766
24832
  async fromBuffer(input) {
24767
24833
  if (!(input instanceof Uint8Array || input instanceof ArrayBuffer)) {
24768
24834
  throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof input}\``);
@@ -24774,20 +24840,14 @@ class FileTypeParser {
24774
24840
  return this.fromTokenizer(fromBuffer(buffer, this.getTokenizerOptions()));
24775
24841
  }
24776
24842
  async fromBlob(blob) {
24843
+ this.options.signal?.throwIfAborted();
24777
24844
  const tokenizer = fromBlob(blob, this.getTokenizerOptions());
24778
- try {
24779
- return await this.fromTokenizer(tokenizer);
24780
- } finally {
24781
- await tokenizer.close();
24782
- }
24845
+ return this.fromTokenizer(tokenizer);
24783
24846
  }
24784
24847
  async fromStream(stream) {
24785
- const tokenizer = fromWebStream(stream, this.getTokenizerOptions());
24786
- try {
24787
- return await this.fromTokenizer(tokenizer);
24788
- } finally {
24789
- await tokenizer.close();
24790
- }
24848
+ this.options.signal?.throwIfAborted();
24849
+ const tokenizer = this.createTokenizerFromWebStream(stream);
24850
+ return this.fromTokenizer(tokenizer);
24791
24851
  }
24792
24852
  async toDetectionStream(stream, options) {
24793
24853
  const sampleSize = normalizeSampleSize(options?.sampleSize ?? reasonableDetectionSizeInBytes);
@@ -24795,7 +24855,7 @@ class FileTypeParser {
24795
24855
  let firstChunk;
24796
24856
  const reader = stream.getReader({ mode: "byob" });
24797
24857
  try {
24798
- const { value: chunk, done } = await reader.read(new Uint8Array(sampleSize));
24858
+ const { value: chunk, done } = await readByobReaderWithSignal(reader, new Uint8Array(sampleSize), this.options.signal);
24799
24859
  firstChunk = chunk;
24800
24860
  if (!done && chunk) {
24801
24861
  try {
@@ -24823,6 +24883,57 @@ class FileTypeParser {
24823
24883
  newStream.fileType = detectedFileType;
24824
24884
  return newStream;
24825
24885
  }
24886
+ async detectGzip(tokenizer) {
24887
+ if (this.gzipProbeDepth >= maximumNestedGzipProbeDepth) {
24888
+ return {
24889
+ ext: "gz",
24890
+ mime: "application/gzip"
24891
+ };
24892
+ }
24893
+ const gzipHandler = new GzipHandler(tokenizer);
24894
+ const limitedInflatedStream = createByteLimitedReadableStream(gzipHandler.inflate(), maximumNestedGzipDetectionSizeInBytes);
24895
+ const hasUnknownSize = hasUnknownFileSize(tokenizer);
24896
+ let timeout;
24897
+ let probeSignal;
24898
+ let probeParser;
24899
+ let compressedFileType;
24900
+ if (hasUnknownSize) {
24901
+ const timeoutController = new AbortController;
24902
+ timeout = setTimeout(() => {
24903
+ timeoutController.abort(new DOMException(`Operation timed out after ${unknownSizeGzipProbeTimeoutInMilliseconds} ms`, "TimeoutError"));
24904
+ }, unknownSizeGzipProbeTimeoutInMilliseconds);
24905
+ probeSignal = this.options.signal === undefined ? timeoutController.signal : AbortSignal.any([this.options.signal, timeoutController.signal]);
24906
+ probeParser = new FileTypeParser({
24907
+ ...this.options,
24908
+ signal: probeSignal
24909
+ });
24910
+ probeParser.gzipProbeDepth = this.gzipProbeDepth + 1;
24911
+ } else {
24912
+ this.gzipProbeDepth++;
24913
+ }
24914
+ try {
24915
+ compressedFileType = await (probeParser ?? this).fromStream(limitedInflatedStream);
24916
+ } catch (error) {
24917
+ if (error?.name === "AbortError" && probeSignal?.reason?.name !== "TimeoutError") {
24918
+ throw error;
24919
+ }
24920
+ } finally {
24921
+ clearTimeout(timeout);
24922
+ if (!hasUnknownSize) {
24923
+ this.gzipProbeDepth--;
24924
+ }
24925
+ }
24926
+ if (compressedFileType?.ext === "tar") {
24927
+ return {
24928
+ ext: "tar.gz",
24929
+ mime: "application/gzip"
24930
+ };
24931
+ }
24932
+ return {
24933
+ ext: "gz",
24934
+ mime: "application/gzip"
24935
+ };
24936
+ }
24826
24937
  check(header, options) {
24827
24938
  return _check(this.buffer, header, options);
24828
24939
  }
@@ -24835,6 +24946,12 @@ class FileTypeParser {
24835
24946
  tokenizer.fileInfo.size = Number.MAX_SAFE_INTEGER;
24836
24947
  }
24837
24948
  this.tokenizer = tokenizer;
24949
+ if (hasUnknownFileSize(tokenizer)) {
24950
+ await tokenizer.peekBuffer(this.buffer, { length: 3, mayBeLess: true });
24951
+ if (this.check([31, 139, 8])) {
24952
+ return this.detectGzip(tokenizer);
24953
+ }
24954
+ }
24838
24955
  await tokenizer.peekBuffer(this.buffer, { length: 32, mayBeLess: true });
24839
24956
  if (this.check([66, 77])) {
24840
24957
  return {
@@ -24912,35 +25029,7 @@ class FileTypeParser {
24912
25029
  };
24913
25030
  }
24914
25031
  if (this.check([31, 139, 8])) {
24915
- if (this.gzipProbeDepth >= maximumNestedGzipProbeDepth) {
24916
- return {
24917
- ext: "gz",
24918
- mime: "application/gzip"
24919
- };
24920
- }
24921
- const gzipHandler = new GzipHandler(tokenizer);
24922
- const limitedInflatedStream = createByteLimitedReadableStream(gzipHandler.inflate(), maximumNestedGzipDetectionSizeInBytes);
24923
- let compressedFileType;
24924
- try {
24925
- this.gzipProbeDepth++;
24926
- compressedFileType = await this.fromStream(limitedInflatedStream);
24927
- } catch (error) {
24928
- if (error?.name === "AbortError") {
24929
- throw error;
24930
- }
24931
- } finally {
24932
- this.gzipProbeDepth--;
24933
- }
24934
- if (compressedFileType?.ext === "tar") {
24935
- return {
24936
- ext: "tar.gz",
24937
- mime: "application/gzip"
24938
- };
24939
- }
24940
- return {
24941
- ext: "gz",
24942
- mime: "application/gzip"
24943
- };
25032
+ return this.detectGzip(tokenizer);
24944
25033
  }
24945
25034
  if (this.check([66, 90, 104])) {
24946
25035
  return {
@@ -24982,7 +25071,7 @@ class FileTypeParser {
24982
25071
  return;
24983
25072
  }
24984
25073
  this.detectionReentryCount++;
24985
- return this.fromTokenizer(tokenizer, this.detectionReentryCount);
25074
+ return this.parseTokenizer(tokenizer, this.detectionReentryCount);
24986
25075
  }
24987
25076
  if (this.checkString("MP+")) {
24988
25077
  return {
@@ -26264,7 +26353,7 @@ class FileTypeParser {
26264
26353
  }
26265
26354
  }
26266
26355
  }
26267
- var reasonableDetectionSizeInBytes = 4100, maximumMpegOffsetTolerance, maximumZipEntrySizeInBytes, maximumZipEntryCount = 1024, maximumZipBufferedReadSizeInBytes, maximumUntrustedSkipSizeInBytes, maximumUnknownSizePayloadProbeSizeInBytes, maximumZipTextEntrySizeInBytes, maximumNestedGzipDetectionSizeInBytes, maximumNestedGzipProbeDepth = 1, maximumId3HeaderSizeInBytes, maximumEbmlDocumentTypeSizeInBytes = 64, maximumEbmlElementPayloadSizeInBytes, maximumEbmlElementCount = 256, maximumPngChunkCount = 512, maximumPngStreamScanBudgetInBytes, maximumAsfHeaderObjectCount = 512, maximumTiffTagCount = 512, maximumDetectionReentryCount = 256, maximumPngChunkSizeInBytes, maximumAsfHeaderPayloadSizeInBytes, maximumTiffStreamIfdOffsetInBytes, maximumTiffIfdOffsetInBytes, recoverableZipErrorMessages, recoverableZipErrorMessagePrefixes, recoverableZipErrorCodes, ParserHardLimitError, zipDataDescriptorSignature = 134695760, zipDataDescriptorLengthInBytes = 16, zipDataDescriptorOverlapLengthInBytes, supportedExtensions, supportedMimeTypes;
26356
+ var reasonableDetectionSizeInBytes = 4100, maximumMpegOffsetTolerance, maximumZipEntrySizeInBytes, maximumZipEntryCount = 1024, maximumZipBufferedReadSizeInBytes, maximumUntrustedSkipSizeInBytes, maximumUnknownSizePayloadProbeSizeInBytes, maximumZipTextEntrySizeInBytes, maximumNestedGzipDetectionSizeInBytes, maximumNestedGzipProbeDepth = 1, unknownSizeGzipProbeTimeoutInMilliseconds = 100, maximumId3HeaderSizeInBytes, maximumEbmlDocumentTypeSizeInBytes = 64, maximumEbmlElementPayloadSizeInBytes, maximumEbmlElementCount = 256, maximumPngChunkCount = 512, maximumPngStreamScanBudgetInBytes, maximumAsfHeaderObjectCount = 512, maximumTiffTagCount = 512, maximumDetectionReentryCount = 256, maximumPngChunkSizeInBytes, maximumAsfHeaderPayloadSizeInBytes, maximumTiffStreamIfdOffsetInBytes, maximumTiffIfdOffsetInBytes, recoverableZipErrorMessages, recoverableZipErrorMessagePrefixes, recoverableZipErrorCodes, ParserHardLimitError, zipDataDescriptorSignature = 134695760, zipDataDescriptorLengthInBytes = 16, zipDataDescriptorOverlapLengthInBytes, supportedExtensions, supportedMimeTypes;
26268
26357
  var init_core2 = __esm(() => {
26269
26358
  init_lib3();
26270
26359
  init_core();
@@ -26295,7 +26384,8 @@ var init_core2 = __esm(() => {
26295
26384
  "ZIP entry count exceeds ",
26296
26385
  "Unsupported ZIP compression method:",
26297
26386
  "ZIP entry compressed data exceeds ",
26298
- "ZIP entry decompressed data exceeds "
26387
+ "ZIP entry decompressed data exceeds ",
26388
+ "Expected data-descriptor-signature at position "
26299
26389
  ];
26300
26390
  recoverableZipErrorCodes = new Set([
26301
26391
  "Z_BUF_ERROR",
@@ -26397,7 +26487,8 @@ var init_file_type = __esm(() => {
26397
26487
  init_core2();
26398
26488
  FileTypeParser2 = class FileTypeParser2 extends FileTypeParser {
26399
26489
  async fromStream(stream) {
26400
- const tokenizer = await (stream instanceof WebReadableStream ? fromWebStream(stream, this.getTokenizerOptions()) : fromStream2(stream, this.getTokenizerOptions()));
26490
+ this.options.signal?.throwIfAborted();
26491
+ const tokenizer = await (stream instanceof WebReadableStream ? this.createTokenizerFromWebStream(stream) : fromStream2(stream, this.getTokenizerOptions()));
26401
26492
  try {
26402
26493
  return await super.fromTokenizer(tokenizer);
26403
26494
  } catch (error) {
@@ -26406,10 +26497,13 @@ var init_file_type = __esm(() => {
26406
26497
  }
26407
26498
  throw error;
26408
26499
  } finally {
26409
- await tokenizer.close();
26500
+ if (stream instanceof Readable && !stream.destroyed) {
26501
+ stream.destroy();
26502
+ }
26410
26503
  }
26411
26504
  }
26412
26505
  async fromFile(path) {
26506
+ this.options.signal?.throwIfAborted();
26413
26507
  const fileHandle = await fs.open(path, fileSystemConstants.O_RDONLY | fileSystemConstants.O_NONBLOCK);
26414
26508
  const fileStat = await fileHandle.stat();
26415
26509
  if (!fileStat.isFile()) {
@@ -26423,41 +26517,65 @@ var init_file_type = __esm(() => {
26423
26517
  size: fileStat.size
26424
26518
  }
26425
26519
  });
26426
- try {
26427
- return await super.fromTokenizer(tokenizer);
26428
- } finally {
26429
- await tokenizer.close();
26430
- }
26520
+ return super.fromTokenizer(tokenizer);
26431
26521
  }
26432
26522
  async toDetectionStream(readableStream, options = {}) {
26433
26523
  if (!(readableStream instanceof Readable)) {
26434
26524
  return super.toDetectionStream(readableStream, options);
26435
26525
  }
26436
- const sampleSize = normalizeSampleSize(options.sampleSize ?? reasonableDetectionSizeInBytes);
26526
+ const { sampleSize = reasonableDetectionSizeInBytes } = options;
26527
+ const { signal } = this.options;
26528
+ const normalizedSampleSize = normalizeSampleSize(sampleSize);
26529
+ signal?.throwIfAborted();
26437
26530
  return new Promise((resolve3, reject) => {
26438
- readableStream.on("error", reject);
26439
- readableStream.once("readable", () => {
26531
+ let isSettled = false;
26532
+ const cleanup = () => {
26533
+ readableStream.off("error", onError);
26534
+ readableStream.off("readable", onReadable);
26535
+ signal?.removeEventListener("abort", onAbort);
26536
+ };
26537
+ const settle = (callback, value) => {
26538
+ if (isSettled) {
26539
+ return;
26540
+ }
26541
+ isSettled = true;
26542
+ cleanup();
26543
+ callback(value);
26544
+ };
26545
+ const onError = (error) => {
26546
+ settle(reject, error);
26547
+ };
26548
+ const onAbort = () => {
26549
+ if (!readableStream.destroyed) {
26550
+ readableStream.destroy();
26551
+ }
26552
+ settle(reject, signal.reason);
26553
+ };
26554
+ const onReadable = () => {
26440
26555
  (async () => {
26441
26556
  try {
26442
26557
  const pass = new PassThrough;
26443
26558
  const outputStream = pipeline ? pipeline(readableStream, pass, () => {
26444
26559
  }) : readableStream.pipe(pass);
26445
- const chunk = readableStream.read(sampleSize) ?? readableStream.read() ?? new Uint8Array(0);
26560
+ const chunk = readableStream.read(normalizedSampleSize) ?? readableStream.read() ?? new Uint8Array(0);
26446
26561
  try {
26447
26562
  pass.fileType = await this.fromBuffer(chunk);
26448
26563
  } catch (error) {
26449
26564
  if (error instanceof EndOfStreamError) {
26450
26565
  pass.fileType = undefined;
26451
26566
  } else {
26452
- reject(error);
26567
+ settle(reject, error);
26453
26568
  }
26454
26569
  }
26455
- resolve3(outputStream);
26570
+ settle(resolve3, outputStream);
26456
26571
  } catch (error) {
26457
- reject(error);
26572
+ settle(reject, error);
26458
26573
  }
26459
26574
  })();
26460
- });
26575
+ };
26576
+ readableStream.on("error", onError);
26577
+ readableStream.once("readable", onReadable);
26578
+ signal?.addEventListener("abort", onAbort, { once: true });
26461
26579
  });
26462
26580
  }
26463
26581
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donezone/cli",
3
- "version": "0.1.44",
3
+ "version": "0.1.46",
4
4
  "doneZoneVersion": "0.1.41",
5
5
  "doneClientVersion": "0.1.41",
6
6
  "private": false,