@push.rocks/smartarchive 5.0.1 → 5.2.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.
Files changed (80) hide show
  1. package/dist_ts/00_commitinfo_data.js +2 -2
  2. package/dist_ts/classes.archiveanalyzer.d.ts +1 -1
  3. package/dist_ts/classes.archiveanalyzer.js +34 -4
  4. package/dist_ts/classes.smartarchive.d.ts +4 -4
  5. package/dist_ts/classes.smartarchive.js +45 -26
  6. package/dist_ts/classes.tartools.d.ts +74 -23
  7. package/dist_ts/classes.tartools.js +190 -139
  8. package/dist_ts/index.d.ts +2 -6
  9. package/dist_ts/index.js +7 -11
  10. package/dist_ts/paths.js +1 -1
  11. package/dist_ts/plugins.d.ts +4 -9
  12. package/dist_ts/plugins.js +9 -13
  13. package/{dist_ts → dist_ts_shared}/bzip2/bititerator.d.ts +1 -1
  14. package/dist_ts_shared/bzip2/bititerator.js +50 -0
  15. package/{dist_ts → dist_ts_shared}/bzip2/bzip2.d.ts +2 -2
  16. package/{dist_ts → dist_ts_shared}/bzip2/bzip2.js +1 -1
  17. package/{dist_ts → dist_ts_shared}/bzip2/index.d.ts +1 -1
  18. package/dist_ts_shared/bzip2/index.js +92 -0
  19. package/dist_ts_shared/classes.bzip2tools.d.ts +10 -0
  20. package/dist_ts_shared/classes.bzip2tools.js +14 -0
  21. package/dist_ts_shared/classes.gziptools.d.ts +26 -0
  22. package/dist_ts_shared/classes.gziptools.js +38 -0
  23. package/dist_ts_shared/classes.tartools.d.ts +30 -0
  24. package/dist_ts_shared/classes.tartools.js +78 -0
  25. package/dist_ts_shared/classes.ziptools.d.ts +31 -0
  26. package/dist_ts_shared/classes.ziptools.js +103 -0
  27. package/{dist_ts → dist_ts_shared}/errors.js +1 -1
  28. package/dist_ts_shared/index.d.ts +8 -0
  29. package/dist_ts_shared/index.js +14 -0
  30. package/{dist_ts → dist_ts_shared}/interfaces.d.ts +17 -7
  31. package/{dist_ts → dist_ts_shared}/interfaces.js +1 -1
  32. package/dist_ts_shared/plugins.d.ts +9 -0
  33. package/dist_ts_shared/plugins.js +14 -0
  34. package/dist_ts_web/00_commitinfo_data.d.ts +8 -0
  35. package/dist_ts_web/00_commitinfo_data.js +9 -0
  36. package/dist_ts_web/index.d.ts +1 -0
  37. package/dist_ts_web/index.js +4 -0
  38. package/dist_ts_web/plugins.d.ts +1 -0
  39. package/dist_ts_web/plugins.js +4 -0
  40. package/npmextra.json +13 -7
  41. package/package.json +24 -13
  42. package/readme.md +154 -46
  43. package/ts/00_commitinfo_data.ts +1 -1
  44. package/ts/classes.archiveanalyzer.ts +33 -5
  45. package/ts/classes.smartarchive.ts +48 -27
  46. package/ts/classes.tartools.ts +217 -153
  47. package/ts/index.ts +7 -11
  48. package/ts/plugins.ts +8 -16
  49. package/{ts → ts_shared}/bzip2/bititerator.ts +1 -1
  50. package/{ts → ts_shared}/bzip2/bzip2.ts +2 -2
  51. package/{ts → ts_shared}/bzip2/index.ts +6 -6
  52. package/ts_shared/classes.bzip2tools.ts +14 -0
  53. package/ts_shared/classes.gziptools.ts +42 -0
  54. package/ts_shared/classes.tartools.ts +89 -0
  55. package/ts_shared/classes.ziptools.ts +107 -0
  56. package/ts_shared/index.ts +17 -0
  57. package/{ts → ts_shared}/interfaces.ts +18 -7
  58. package/ts_shared/plugins.ts +22 -0
  59. package/ts_web/00_commitinfo_data.ts +8 -0
  60. package/ts_web/index.ts +4 -0
  61. package/ts_web/plugins.ts +3 -0
  62. package/dist_ts/bzip2/bititerator.js +0 -50
  63. package/dist_ts/bzip2/index.js +0 -92
  64. package/dist_ts/classes.bzip2tools.d.ts +0 -7
  65. package/dist_ts/classes.bzip2tools.js +0 -11
  66. package/dist_ts/classes.gziptools.d.ts +0 -53
  67. package/dist_ts/classes.gziptools.js +0 -116
  68. package/dist_ts/classes.ziptools.d.ts +0 -56
  69. package/dist_ts/classes.ziptools.js +0 -171
  70. package/dist_ts/smartarchive.classes.smartarchive.d.ts +0 -34
  71. package/dist_ts/smartarchive.classes.smartarchive.js +0 -116
  72. package/dist_ts/smartarchive.paths.d.ts +0 -2
  73. package/dist_ts/smartarchive.paths.js +0 -4
  74. package/dist_ts/smartarchive.plugins.d.ts +0 -14
  75. package/dist_ts/smartarchive.plugins.js +0 -19
  76. package/ts/classes.bzip2tools.ts +0 -16
  77. package/ts/classes.gziptools.ts +0 -138
  78. package/ts/classes.ziptools.ts +0 -196
  79. /package/{dist_ts → dist_ts_shared}/errors.d.ts +0 -0
  80. /package/{ts → ts_shared}/errors.ts +0 -0
@@ -8,16 +8,16 @@ import { bitIterator } from './bititerator.js';
8
8
  /**
9
9
  * Creates a streaming BZIP2 decompression transform
10
10
  */
11
- export function unbzip2Stream(): plugins.smartstream.SmartDuplex<Buffer, Buffer> {
11
+ export function unbzip2Stream(): plugins.smartstream.SmartDuplex<Uint8Array, Uint8Array> {
12
12
  const bzip2Instance = new Bzip2();
13
- const bufferQueue: Buffer[] = [];
13
+ const bufferQueue: Uint8Array[] = [];
14
14
  let hasBytes = 0;
15
15
  let blockSize = 0;
16
16
  let broken = false;
17
17
  let bitReader: IBitReader | null = null;
18
18
  let streamCRC: number | null = null;
19
19
 
20
- function decompressBlock(): Buffer | undefined {
20
+ function decompressBlock(): Uint8Array | undefined {
21
21
  if (!blockSize) {
22
22
  blockSize = bzip2Instance.header(bitReader!);
23
23
  streamCRC = 0;
@@ -40,12 +40,12 @@ export function unbzip2Stream(): plugins.smartstream.SmartDuplex<Buffer, Buffer>
40
40
  return undefined;
41
41
  }
42
42
 
43
- return Buffer.from(chunk);
43
+ return new Uint8Array(chunk);
44
44
  }
45
45
 
46
46
  let outlength = 0;
47
47
 
48
- const decompressAndPush = async (): Promise<Buffer | undefined> => {
48
+ const decompressAndPush = async (): Promise<Uint8Array | undefined> => {
49
49
  if (broken) return undefined;
50
50
 
51
51
  try {
@@ -63,7 +63,7 @@ export function unbzip2Stream(): plugins.smartstream.SmartDuplex<Buffer, Buffer>
63
63
  }
64
64
  };
65
65
 
66
- return new plugins.smartstream.SmartDuplex<Buffer, Buffer>({
66
+ return new plugins.smartstream.SmartDuplex<Uint8Array, Uint8Array>({
67
67
  objectMode: true,
68
68
  name: 'bzip2',
69
69
  highWaterMark: 1,
@@ -0,0 +1,14 @@
1
+ import * as plugins from './plugins.js';
2
+ import { unbzip2Stream } from './bzip2/index.js';
3
+
4
+ /**
5
+ * BZIP2 decompression utilities (browser-compatible)
6
+ */
7
+ export class Bzip2Tools {
8
+ /**
9
+ * Get a streaming decompression transform
10
+ */
11
+ getDecompressionStream(): plugins.smartstream.SmartDuplex<Uint8Array, Uint8Array> {
12
+ return unbzip2Stream();
13
+ }
14
+ }
@@ -0,0 +1,42 @@
1
+ import * as plugins from './plugins.js';
2
+ import type { TCompressionLevel } from './interfaces.js';
3
+
4
+ /**
5
+ * GZIP compression and decompression utilities (browser-compatible)
6
+ */
7
+ export class GzipTools {
8
+ /**
9
+ * Compress data synchronously
10
+ */
11
+ public compressSync(data: Uint8Array, level?: TCompressionLevel): Uint8Array {
12
+ const options = level !== undefined ? { level } : undefined;
13
+ return plugins.fflate.gzipSync(data, options);
14
+ }
15
+
16
+ /**
17
+ * Decompress data synchronously
18
+ */
19
+ public decompressSync(data: Uint8Array): Uint8Array {
20
+ return plugins.fflate.gunzipSync(data);
21
+ }
22
+
23
+ /**
24
+ * Compress data asynchronously
25
+ * Note: Uses sync version for Deno compatibility (fflate async uses Web Workers
26
+ * which have issues in Deno)
27
+ */
28
+ public async compress(data: Uint8Array, level?: TCompressionLevel): Promise<Uint8Array> {
29
+ // Use sync version wrapped in Promise for cross-runtime compatibility
30
+ return this.compressSync(data, level);
31
+ }
32
+
33
+ /**
34
+ * Decompress data asynchronously
35
+ * Note: Uses sync version for Deno compatibility (fflate async uses Web Workers
36
+ * which have issues in Deno)
37
+ */
38
+ public async decompress(data: Uint8Array): Promise<Uint8Array> {
39
+ // Use sync version wrapped in Promise for cross-runtime compatibility
40
+ return this.decompressSync(data);
41
+ }
42
+ }
@@ -0,0 +1,89 @@
1
+ import * as plugins from './plugins.js';
2
+ import type { IArchiveEntry, ITarEntry, TCompressionLevel } from './interfaces.js';
3
+ import { GzipTools } from './classes.gziptools.js';
4
+
5
+ /**
6
+ * TAR archive creation and extraction utilities using modern-tar (browser-compatible)
7
+ */
8
+ export class TarTools {
9
+ /**
10
+ * Pack files into a TAR buffer
11
+ */
12
+ public async packFiles(files: IArchiveEntry[]): Promise<Uint8Array> {
13
+ const entries: ITarEntry[] = [];
14
+
15
+ for (const file of files) {
16
+ let data: Uint8Array;
17
+
18
+ if (typeof file.content === 'string') {
19
+ data = new TextEncoder().encode(file.content);
20
+ } else if (file.content instanceof Uint8Array) {
21
+ data = file.content;
22
+ } else if (file.content instanceof plugins.smartfile.SmartFile) {
23
+ data = new Uint8Array(file.content.contents);
24
+ } else if (file.content instanceof plugins.smartfile.StreamFile) {
25
+ const buffer = await file.content.getContentAsBuffer();
26
+ data = new Uint8Array(buffer);
27
+ } else {
28
+ throw new Error('Unsupported content type for TAR entry');
29
+ }
30
+
31
+ entries.push({
32
+ header: {
33
+ name: file.archivePath,
34
+ size: data.length,
35
+ type: 'file',
36
+ mode: file.mode,
37
+ mtime: file.mtime,
38
+ },
39
+ body: data,
40
+ });
41
+ }
42
+
43
+ return plugins.modernTar.packTar(entries);
44
+ }
45
+
46
+ /**
47
+ * Extract a TAR buffer to an array of entries
48
+ */
49
+ public async extractTar(data: Uint8Array): Promise<Array<{ path: string; content: Uint8Array; isDirectory: boolean }>> {
50
+ const entries = await plugins.modernTar.unpackTar(data);
51
+ const result: Array<{ path: string; content: Uint8Array; isDirectory: boolean }> = [];
52
+
53
+ for (const entry of entries) {
54
+ const isDirectory = entry.header.type === 'directory' || entry.header.name.endsWith('/');
55
+
56
+ // modern-tar uses 'data' property, not 'body'
57
+ const content = entry.data ?? new Uint8Array(0);
58
+
59
+ result.push({
60
+ path: entry.header.name,
61
+ content,
62
+ isDirectory,
63
+ });
64
+ }
65
+
66
+ return result;
67
+ }
68
+
69
+ /**
70
+ * Pack files into a TAR.GZ buffer
71
+ */
72
+ public async packFilesToTarGz(
73
+ files: IArchiveEntry[],
74
+ compressionLevel?: TCompressionLevel
75
+ ): Promise<Uint8Array> {
76
+ const tarBuffer = await this.packFiles(files);
77
+ const gzipTools = new GzipTools();
78
+ return gzipTools.compress(tarBuffer, compressionLevel);
79
+ }
80
+
81
+ /**
82
+ * Extract a TAR.GZ buffer to an array of entries
83
+ */
84
+ public async extractTarGz(data: Uint8Array): Promise<Array<{ path: string; content: Uint8Array; isDirectory: boolean }>> {
85
+ const gzipTools = new GzipTools();
86
+ const tarBuffer = await gzipTools.decompress(data);
87
+ return this.extractTar(tarBuffer);
88
+ }
89
+ }
@@ -0,0 +1,107 @@
1
+ import * as plugins from './plugins.js';
2
+ import type { IArchiveEntry, TCompressionLevel } from './interfaces.js';
3
+
4
+ /**
5
+ * Transform stream for ZIP decompression using fflate
6
+ * Emits StreamFile objects for each file in the archive
7
+ */
8
+ export class ZipDecompressionTransform extends plugins.smartstream.SmartDuplex<Uint8Array, plugins.smartfile.StreamFile> {
9
+ private streamtools!: plugins.smartstream.IStreamTools;
10
+ private unzipper = new plugins.fflate.Unzip(async (fileArg) => {
11
+ let resultBuffer: Uint8Array;
12
+ fileArg.ondata = async (_flateError, dat, final) => {
13
+ if (resultBuffer) {
14
+ const combined = new Uint8Array(resultBuffer.length + dat.length);
15
+ combined.set(resultBuffer);
16
+ combined.set(dat, resultBuffer.length);
17
+ resultBuffer = combined;
18
+ } else {
19
+ resultBuffer = new Uint8Array(dat);
20
+ }
21
+ if (final) {
22
+ const streamFile = plugins.smartfile.StreamFile.fromBuffer(Buffer.from(resultBuffer));
23
+ streamFile.relativeFilePath = fileArg.name;
24
+ this.streamtools.push(streamFile);
25
+ }
26
+ };
27
+ fileArg.start();
28
+ });
29
+
30
+ constructor() {
31
+ super({
32
+ objectMode: true,
33
+ writeFunction: async (chunkArg, streamtoolsArg) => {
34
+ this.streamtools ? null : (this.streamtools = streamtoolsArg);
35
+ const chunk = chunkArg instanceof Uint8Array ? chunkArg : new Uint8Array(chunkArg);
36
+ this.unzipper.push(chunk, false);
37
+ return null;
38
+ },
39
+ finalFunction: async () => {
40
+ this.unzipper.push(new Uint8Array(0), true);
41
+ await plugins.smartdelay.delayFor(0);
42
+ await this.streamtools.push(null);
43
+ return null;
44
+ },
45
+ });
46
+ this.unzipper.register(plugins.fflate.UnzipInflate);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * ZIP compression and decompression utilities
52
+ */
53
+ export class ZipTools {
54
+ /**
55
+ * Get a streaming decompression transform for extracting ZIP archives
56
+ */
57
+ public getDecompressionStream(): ZipDecompressionTransform {
58
+ return new ZipDecompressionTransform();
59
+ }
60
+
61
+ /**
62
+ * Create a ZIP archive from an array of entries
63
+ */
64
+ public async createZip(entries: IArchiveEntry[], compressionLevel?: TCompressionLevel): Promise<Uint8Array> {
65
+ const filesObj: plugins.fflate.Zippable = {};
66
+
67
+ for (const entry of entries) {
68
+ let data: Uint8Array;
69
+
70
+ if (typeof entry.content === 'string') {
71
+ data = new TextEncoder().encode(entry.content);
72
+ } else if (entry.content instanceof Uint8Array) {
73
+ data = entry.content;
74
+ } else if (entry.content instanceof plugins.smartfile.SmartFile) {
75
+ data = new Uint8Array(entry.content.contents);
76
+ } else if (entry.content instanceof plugins.smartfile.StreamFile) {
77
+ const buffer = await entry.content.getContentAsBuffer();
78
+ data = new Uint8Array(buffer);
79
+ } else {
80
+ throw new Error('Unsupported content type for ZIP entry');
81
+ }
82
+
83
+ if (compressionLevel !== undefined) {
84
+ filesObj[entry.archivePath] = [data, { level: compressionLevel }];
85
+ } else {
86
+ filesObj[entry.archivePath] = data;
87
+ }
88
+ }
89
+
90
+ // Use sync version for Deno compatibility (fflate async uses Web Workers)
91
+ const result = plugins.fflate.zipSync(filesObj);
92
+ return result;
93
+ }
94
+
95
+ /**
96
+ * Extract a ZIP buffer to an array of entries
97
+ */
98
+ public async extractZip(data: Uint8Array): Promise<Array<{ path: string; content: Uint8Array }>> {
99
+ // Use sync version for Deno compatibility (fflate async uses Web Workers)
100
+ const result = plugins.fflate.unzipSync(data);
101
+ const entries: Array<{ path: string; content: Uint8Array }> = [];
102
+ for (const [path, content] of Object.entries(result)) {
103
+ entries.push({ path, content });
104
+ }
105
+ return entries;
106
+ }
107
+ }
@@ -0,0 +1,17 @@
1
+ // ts_shared - Browser-compatible shared code
2
+
3
+ // Interfaces and types
4
+ export * from './interfaces.js';
5
+
6
+ // Error classes
7
+ export * from './errors.js';
8
+
9
+ // Tool classes
10
+ export { ZipTools, ZipDecompressionTransform } from './classes.ziptools.js';
11
+ export { GzipTools } from './classes.gziptools.js';
12
+ export { TarTools } from './classes.tartools.js';
13
+ export { Bzip2Tools } from './classes.bzip2tools.js';
14
+
15
+ // BZIP2 internals (for advanced usage)
16
+ export { unbzip2Stream } from './bzip2/index.js';
17
+ export { Bzip2 } from './bzip2/bzip2.js';
@@ -1,4 +1,3 @@
1
- import type * as stream from 'node:stream';
2
1
  import type { SmartFile, StreamFile } from '@push.rocks/smartfile';
3
2
 
4
3
  /**
@@ -22,13 +21,13 @@ export type TSupportedMime =
22
21
  | undefined;
23
22
 
24
23
  /**
25
- * Entry to add to an archive during creation
24
+ * Entry to add to an archive during creation (browser-compatible)
26
25
  */
27
26
  export interface IArchiveEntry {
28
27
  /** Path within the archive */
29
28
  archivePath: string;
30
- /** Content: string, Buffer, Readable stream, SmartFile, or StreamFile */
31
- content: string | Buffer | stream.Readable | SmartFile | StreamFile;
29
+ /** Content: string, Buffer/Uint8Array, SmartFile, or StreamFile */
30
+ content: string | Uint8Array | SmartFile | StreamFile;
32
31
  /** Optional size hint for streams (improves performance) */
33
32
  size?: number;
34
33
  /** Optional file mode/permissions */
@@ -104,11 +103,9 @@ export interface IAddFileOptions {
104
103
  /** Filename within the archive */
105
104
  fileName?: string;
106
105
  /** File content */
107
- content?: string | Buffer | stream.Readable | SmartFile | StreamFile;
106
+ content?: string | Uint8Array | SmartFile | StreamFile;
108
107
  /** Size in bytes (required for streams) */
109
108
  byteLength?: number;
110
- /** Path to file on disk (alternative to content) */
111
- filePath?: string;
112
109
  }
113
110
 
114
111
  /**
@@ -134,3 +131,17 @@ export interface IHuffmanGroup {
134
131
  * Entry filter predicate for fluent API
135
132
  */
136
133
  export type TEntryFilter = (entry: IArchiveEntryInfo) => boolean;
134
+
135
+ /**
136
+ * TAR entry for modern-tar compatibility
137
+ */
138
+ export interface ITarEntry {
139
+ header: {
140
+ name: string;
141
+ size: number;
142
+ type?: 'file' | 'directory';
143
+ mode?: number;
144
+ mtime?: Date;
145
+ };
146
+ body: string | Uint8Array;
147
+ }
@@ -0,0 +1,22 @@
1
+ // Browser-compatible plugins for ts_shared
2
+ // NO Node.js imports allowed here
3
+
4
+ // @push.rocks scope (browser-compatible)
5
+ import * as smartdelay from '@push.rocks/smartdelay';
6
+ import * as smartpromise from '@push.rocks/smartpromise';
7
+ import * as smartstream from '@push.rocks/smartstream';
8
+ import * as smartfile from '@push.rocks/smartfile';
9
+
10
+ export {
11
+ smartdelay,
12
+ smartpromise,
13
+ smartstream,
14
+ smartfile,
15
+ };
16
+
17
+ // third party scope (browser-compatible)
18
+ import * as fileType from 'file-type';
19
+ import * as fflate from 'fflate';
20
+ import * as modernTar from 'modern-tar';
21
+
22
+ export { fileType, fflate, modernTar };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * autocreated commitinfo by @push.rocks/commitinfo
3
+ */
4
+ export const commitinfo = {
5
+ name: '@push.rocks/smartarchive',
6
+ version: '5.2.0',
7
+ description: 'A library for working with archive files, providing utilities for compressing and decompressing data.'
8
+ }
@@ -0,0 +1,4 @@
1
+ // ts_web - Browser-compatible entry point
2
+ // Re-exports everything from ts_shared
3
+
4
+ export * from '../ts_shared/index.js';
@@ -0,0 +1,3 @@
1
+ // Browser-compatible plugins for ts_web
2
+ // Re-export from ts_shared
3
+ export * from '../ts_shared/plugins.js';
@@ -1,50 +0,0 @@
1
- const BITMASK = [0, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff];
2
- /**
3
- * Creates a bit reader function for BZIP2 decompression.
4
- * Takes a buffer iterator as input and returns a function that reads bits.
5
- */
6
- export function bitIterator(nextBuffer) {
7
- let bit = 0;
8
- let byte = 0;
9
- let bytes = nextBuffer();
10
- let _bytesRead = 0;
11
- const reader = function (n) {
12
- if (n === null && bit !== 0) {
13
- // align to byte boundary
14
- bit = 0;
15
- byte++;
16
- return;
17
- }
18
- let result = 0;
19
- let remaining = n;
20
- while (remaining > 0) {
21
- if (byte >= bytes.length) {
22
- byte = 0;
23
- bytes = nextBuffer();
24
- }
25
- const left = 8 - bit;
26
- if (bit === 0 && remaining > 0) {
27
- _bytesRead++;
28
- }
29
- if (remaining >= left) {
30
- result <<= left;
31
- result |= BITMASK[left] & bytes[byte++];
32
- bit = 0;
33
- remaining -= left;
34
- }
35
- else {
36
- result <<= remaining;
37
- result |= (bytes[byte] & (BITMASK[remaining] << (8 - remaining - bit))) >> (8 - remaining - bit);
38
- bit += remaining;
39
- remaining = 0;
40
- }
41
- }
42
- return result;
43
- };
44
- Object.defineProperty(reader, 'bytesRead', {
45
- get: () => _bytesRead,
46
- enumerable: true,
47
- });
48
- return reader;
49
- }
50
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYml0aXRlcmF0b3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90cy9iemlwMi9iaXRpdGVyYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxNQUFNLE9BQU8sR0FBRyxDQUFDLENBQUMsRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLElBQUksRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLElBQUksRUFBRSxJQUFJLEVBQUUsSUFBSSxDQUFVLENBQUM7QUFFN0U7OztHQUdHO0FBQ0gsTUFBTSxVQUFVLFdBQVcsQ0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0FBQyxDQUFDO2dCQUNSLFNBQVMsSUFBSSxJQUFJLENBQUM7WUFDcEIsQ0FBQztpQkFBTSxDQUFDO2dCQUNOLE1BQU0sS0FBSyxTQUFTLENBQUM7Z0JBQ3JCLE1BQU0sSUFBSSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLENBQUMsR0FBRyxTQUFTLEdBQUcsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxHQUFHLFNBQVMsR0FBRyxHQUFHLENBQUMsQ0FBQztnQkFDakcsR0FBRyxJQUFJLFNBQVMsQ0FBQztnQkFDakIsU0FBUyxHQUFHLENBQUMsQ0FBQztZQUNoQixDQUFDO1FBQ0gsQ0FBQztRQUVELE9BQU8sTUFBTSxDQUFDO0lBQ2hCLENBQWUsQ0FBQztJQUVoQixNQUFNLENBQUMsY0FBYyxDQUFDLE1BQU0sRUFBRSxXQUFXLEVBQUU7UUFDekMsR0FBRyxFQUFFLEdBQUcsRUFBRSxDQUFDLFVBQVU7UUFDckIsVUFBVSxFQUFFLElBQUk7S0FDakIsQ0FBQyxDQUFDO0lBRUgsT0FBTyxNQUFNLENBQUM7QUFDaEIsQ0FBQyJ9
@@ -1,92 +0,0 @@
1
- import * as plugins from '../plugins.js';
2
- import { Bzip2Error, BZIP2_ERROR_CODES } from '../errors.js';
3
- import { Bzip2 } from './bzip2.js';
4
- import { bitIterator } from './bititerator.js';
5
- /**
6
- * Creates a streaming BZIP2 decompression transform
7
- */
8
- export function unbzip2Stream() {
9
- const bzip2Instance = new Bzip2();
10
- const bufferQueue = [];
11
- let hasBytes = 0;
12
- let blockSize = 0;
13
- let broken = false;
14
- let bitReader = null;
15
- let streamCRC = null;
16
- function decompressBlock() {
17
- if (!blockSize) {
18
- blockSize = bzip2Instance.header(bitReader);
19
- streamCRC = 0;
20
- return undefined;
21
- }
22
- const bufsize = 100000 * blockSize;
23
- const buf = new Int32Array(bufsize);
24
- const chunk = [];
25
- const outputFunc = (b) => {
26
- chunk.push(b);
27
- };
28
- streamCRC = bzip2Instance.decompress(bitReader, outputFunc, buf, bufsize, streamCRC);
29
- if (streamCRC === null) {
30
- // Reset for next bzip2 header
31
- blockSize = 0;
32
- return undefined;
33
- }
34
- return Buffer.from(chunk);
35
- }
36
- let outlength = 0;
37
- const decompressAndPush = async () => {
38
- if (broken)
39
- return undefined;
40
- try {
41
- const resultChunk = decompressBlock();
42
- if (resultChunk) {
43
- outlength += resultChunk.length;
44
- }
45
- return resultChunk;
46
- }
47
- catch (e) {
48
- broken = true;
49
- if (e instanceof Error) {
50
- throw new Bzip2Error(`Decompression failed: ${e.message}`, BZIP2_ERROR_CODES.INVALID_BLOCK_DATA);
51
- }
52
- throw e;
53
- }
54
- };
55
- return new plugins.smartstream.SmartDuplex({
56
- objectMode: true,
57
- name: 'bzip2',
58
- highWaterMark: 1,
59
- writeFunction: async function (data, streamTools) {
60
- bufferQueue.push(data);
61
- hasBytes += data.length;
62
- if (bitReader === null) {
63
- bitReader = bitIterator(function () {
64
- return bufferQueue.shift();
65
- });
66
- }
67
- const threshold = 25000 + 100000 * blockSize || 4;
68
- while (!broken && hasBytes - bitReader.bytesRead + 1 >= threshold) {
69
- const result = await decompressAndPush();
70
- if (!result) {
71
- continue;
72
- }
73
- await streamTools.push(result);
74
- }
75
- return null;
76
- },
77
- finalFunction: async function (streamTools) {
78
- while (!broken && bitReader && hasBytes > bitReader.bytesRead) {
79
- const result = await decompressAndPush();
80
- if (!result) {
81
- continue;
82
- }
83
- await streamTools.push(result);
84
- }
85
- if (!broken && streamCRC !== null) {
86
- this.emit('error', new Bzip2Error('Input stream ended prematurely', BZIP2_ERROR_CODES.PREMATURE_END));
87
- }
88
- return null;
89
- },
90
- });
91
- }
92
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290I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xJQUFJLFFBQVEsR0FBRyxTQUFTLENBQUMsU0FBUyxFQUFFLENBQUM7Z0JBQzlELE1BQU0sTUFBTSxHQUFHLE1BQU0saUJBQWlCLEVBQUUsQ0FBQztnQkFDekMsSUFBSSxDQUFDLE1BQU0sRUFBRSxDQUFDO29CQUNaLFNBQVM7Z0JBQ1gsQ0FBQztnQkFDRCxNQUFNLFdBQVcsQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFDLENBQUM7WUFDakMsQ0FBQztZQUVELElBQUksQ0FBQyxNQUFNLElBQUksU0FBUyxLQUFLLElBQUksRUFBRSxDQUFDO2dCQUNsQyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRSxJQUFJLFVBQVUsQ0FBQyxnQ0FBZ0MsRUFBRSxpQkFBaUIsQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFDO1lBQ3hHLENBQUM7WUFDRCxPQUFPLElBQUksQ0FBQztRQUNkLENBQUM7S0FDRixDQUFDLENBQUM7QUFDTCxDQUFDIn0=
@@ -1,7 +0,0 @@
1
- import type { SmartArchive } from './classes.smartarchive.js';
2
- import * as plugins from './plugins.js';
3
- export declare class Bzip2Tools {
4
- smartArchiveRef: SmartArchive;
5
- constructor(smartArchiveRefArg: SmartArchive);
6
- getDecompressionStream(): plugins.smartstream.SmartDuplex<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
7
- }
@@ -1,11 +0,0 @@
1
- import * as plugins from './plugins.js';
2
- import { unbzip2Stream } from './bzip2/index.js';
3
- export class Bzip2Tools {
4
- constructor(smartArchiveRefArg) {
5
- this.smartArchiveRef = smartArchiveRefArg;
6
- }
7
- getDecompressionStream() {
8
- return unbzip2Stream();
9
- }
10
- }
11
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5iemlwMnRvb2xzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvY2xhc3Nlcy5iemlwMnRvb2xzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxPQUFPLE1BQU0sY0FBYyxDQUFDO0FBRXhDLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUVqRCxNQUFNLE9BQU8sVUFBVTtJQUdyQixZQUFZLGtCQUFnQztRQUMxQyxJQUFJLENBQUMsZUFBZSxHQUFHLGtCQUFrQixDQUFDO0lBQzVDLENBQUM7SUFFRCxzQkFBc0I7UUFDcEIsT0FBTyxhQUFhLEVBQUUsQ0FBQztJQUN6QixDQUFDO0NBQ0YifQ==
@@ -1,53 +0,0 @@
1
- import * as plugins from './plugins.js';
2
- import type { TCompressionLevel } from './interfaces.js';
3
- /**
4
- * Transform stream for GZIP compression using fflate
5
- */
6
- export declare class GzipCompressionTransform extends plugins.stream.Transform {
7
- private gzip;
8
- constructor(level?: TCompressionLevel);
9
- _transform(chunk: Buffer, encoding: BufferEncoding, callback: plugins.stream.TransformCallback): void;
10
- _flush(callback: plugins.stream.TransformCallback): void;
11
- }
12
- /**
13
- * Transform stream for GZIP decompression using fflate
14
- */
15
- export declare class GzipDecompressionTransform extends plugins.stream.Transform {
16
- private gunzip;
17
- constructor();
18
- _transform(chunk: Buffer, encoding: BufferEncoding, callback: plugins.stream.TransformCallback): void;
19
- _flush(callback: plugins.stream.TransformCallback): void;
20
- }
21
- /**
22
- * GZIP compression and decompression utilities
23
- */
24
- export declare class GzipTools {
25
- /**
26
- * Get a streaming compression transform
27
- */
28
- getCompressionStream(level?: TCompressionLevel): plugins.stream.Transform;
29
- /**
30
- * Get a streaming decompression transform
31
- */
32
- getDecompressionStream(): plugins.stream.Transform;
33
- /**
34
- * Compress data synchronously
35
- */
36
- compressSync(data: Buffer, level?: TCompressionLevel): Buffer;
37
- /**
38
- * Decompress data synchronously
39
- */
40
- decompressSync(data: Buffer): Buffer;
41
- /**
42
- * Compress data asynchronously
43
- * Note: Uses sync version for Deno compatibility (fflate async uses Web Workers
44
- * which have issues in Deno)
45
- */
46
- compress(data: Buffer, level?: TCompressionLevel): Promise<Buffer>;
47
- /**
48
- * Decompress data asynchronously
49
- * Note: Uses sync version for Deno compatibility (fflate async uses Web Workers
50
- * which have issues in Deno)
51
- */
52
- decompress(data: Buffer): Promise<Buffer>;
53
- }