@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
@@ -1,138 +0,0 @@
1
- import * as plugins from './plugins.js';
2
- import type { TCompressionLevel } from './interfaces.js';
3
-
4
- /**
5
- * Transform stream for GZIP compression using fflate
6
- */
7
- export class GzipCompressionTransform extends plugins.stream.Transform {
8
- private gzip: plugins.fflate.Gzip;
9
-
10
- constructor(level: TCompressionLevel = 6) {
11
- super();
12
-
13
- // Create a streaming Gzip compressor
14
- this.gzip = new plugins.fflate.Gzip({ level }, (chunk, final) => {
15
- this.push(Buffer.from(chunk));
16
- if (final) {
17
- this.push(null);
18
- }
19
- });
20
- }
21
-
22
- _transform(
23
- chunk: Buffer,
24
- encoding: BufferEncoding,
25
- callback: plugins.stream.TransformCallback
26
- ): void {
27
- try {
28
- this.gzip.push(chunk, false);
29
- callback();
30
- } catch (err) {
31
- callback(err as Error);
32
- }
33
- }
34
-
35
- _flush(callback: plugins.stream.TransformCallback): void {
36
- try {
37
- this.gzip.push(new Uint8Array(0), true);
38
- callback();
39
- } catch (err) {
40
- callback(err as Error);
41
- }
42
- }
43
- }
44
-
45
- /**
46
- * Transform stream for GZIP decompression using fflate
47
- */
48
- export class GzipDecompressionTransform extends plugins.stream.Transform {
49
- private gunzip: plugins.fflate.Gunzip;
50
-
51
- constructor() {
52
- super();
53
-
54
- // Create a streaming Gunzip decompressor
55
- this.gunzip = new plugins.fflate.Gunzip((chunk, final) => {
56
- this.push(Buffer.from(chunk));
57
- if (final) {
58
- this.push(null);
59
- }
60
- });
61
- }
62
-
63
- _transform(
64
- chunk: Buffer,
65
- encoding: BufferEncoding,
66
- callback: plugins.stream.TransformCallback
67
- ): void {
68
- try {
69
- this.gunzip.push(chunk, false);
70
- callback();
71
- } catch (err) {
72
- callback(err as Error);
73
- }
74
- }
75
-
76
- _flush(callback: plugins.stream.TransformCallback): void {
77
- try {
78
- this.gunzip.push(new Uint8Array(0), true);
79
- callback();
80
- } catch (err) {
81
- callback(err as Error);
82
- }
83
- }
84
- }
85
-
86
- /**
87
- * GZIP compression and decompression utilities
88
- */
89
- export class GzipTools {
90
- /**
91
- * Get a streaming compression transform
92
- */
93
- public getCompressionStream(level?: TCompressionLevel): plugins.stream.Transform {
94
- return new GzipCompressionTransform(level);
95
- }
96
-
97
- /**
98
- * Get a streaming decompression transform
99
- */
100
- public getDecompressionStream(): plugins.stream.Transform {
101
- return new GzipDecompressionTransform();
102
- }
103
-
104
- /**
105
- * Compress data synchronously
106
- */
107
- public compressSync(data: Buffer, level?: TCompressionLevel): Buffer {
108
- const options = level !== undefined ? { level } : undefined;
109
- return Buffer.from(plugins.fflate.gzipSync(data, options));
110
- }
111
-
112
- /**
113
- * Decompress data synchronously
114
- */
115
- public decompressSync(data: Buffer): Buffer {
116
- return Buffer.from(plugins.fflate.gunzipSync(data));
117
- }
118
-
119
- /**
120
- * Compress data asynchronously
121
- * Note: Uses sync version for Deno compatibility (fflate async uses Web Workers
122
- * which have issues in Deno)
123
- */
124
- public async compress(data: Buffer, level?: TCompressionLevel): Promise<Buffer> {
125
- // Use sync version wrapped in Promise for cross-runtime compatibility
126
- return this.compressSync(data, level);
127
- }
128
-
129
- /**
130
- * Decompress data asynchronously
131
- * Note: Uses sync version for Deno compatibility (fflate async uses Web Workers
132
- * which have issues in Deno)
133
- */
134
- public async decompress(data: Buffer): Promise<Buffer> {
135
- // Use sync version wrapped in Promise for cross-runtime compatibility
136
- return this.decompressSync(data);
137
- }
138
- }
@@ -1,196 +0,0 @@
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<Buffer, plugins.smartfile.StreamFile> {
9
- private streamtools!: plugins.smartstream.IStreamTools;
10
- private unzipper = new plugins.fflate.Unzip(async (fileArg) => {
11
- let resultBuffer: Buffer;
12
- fileArg.ondata = async (_flateError, dat, final) => {
13
- resultBuffer
14
- ? (resultBuffer = Buffer.concat([resultBuffer, Buffer.from(dat)]))
15
- : (resultBuffer = Buffer.from(dat));
16
- if (final) {
17
- const streamFile = plugins.smartfile.StreamFile.fromBuffer(resultBuffer);
18
- streamFile.relativeFilePath = fileArg.name;
19
- this.streamtools.push(streamFile);
20
- }
21
- };
22
- fileArg.start();
23
- });
24
-
25
- constructor() {
26
- super({
27
- objectMode: true,
28
- writeFunction: async (chunkArg, streamtoolsArg) => {
29
- this.streamtools ? null : (this.streamtools = streamtoolsArg);
30
- this.unzipper.push(
31
- Buffer.isBuffer(chunkArg) ? chunkArg : Buffer.from(chunkArg as unknown as ArrayBuffer),
32
- false
33
- );
34
- return null;
35
- },
36
- finalFunction: async () => {
37
- this.unzipper.push(Buffer.from(''), true);
38
- await plugins.smartdelay.delayFor(0);
39
- await this.streamtools.push(null);
40
- return null;
41
- },
42
- });
43
- this.unzipper.register(plugins.fflate.UnzipInflate);
44
- }
45
- }
46
-
47
- /**
48
- * Streaming ZIP compression using fflate
49
- * Allows adding multiple entries before finalizing
50
- */
51
- export class ZipCompressionStream extends plugins.stream.Duplex {
52
- private files: Map<string, { data: Uint8Array; options?: plugins.fflate.ZipOptions }> = new Map();
53
- private finalized = false;
54
-
55
- constructor() {
56
- super();
57
- }
58
-
59
- /**
60
- * Add a file entry to the ZIP archive
61
- */
62
- public async addEntry(
63
- fileName: string,
64
- content: Buffer | plugins.stream.Readable,
65
- options?: { compressionLevel?: TCompressionLevel }
66
- ): Promise<void> {
67
- if (this.finalized) {
68
- throw new Error('Cannot add entries to a finalized ZIP archive');
69
- }
70
-
71
- let data: Buffer;
72
- if (Buffer.isBuffer(content)) {
73
- data = content;
74
- } else {
75
- // Collect stream to buffer
76
- const chunks: Buffer[] = [];
77
- for await (const chunk of content) {
78
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
79
- }
80
- data = Buffer.concat(chunks);
81
- }
82
-
83
- this.files.set(fileName, {
84
- data: new Uint8Array(data),
85
- options: options?.compressionLevel !== undefined ? { level: options.compressionLevel } : undefined,
86
- });
87
- }
88
-
89
- /**
90
- * Finalize the ZIP archive and emit the compressed data
91
- */
92
- public async finalize(): Promise<void> {
93
- if (this.finalized) {
94
- return;
95
- }
96
- this.finalized = true;
97
-
98
- const filesObj: plugins.fflate.Zippable = {};
99
- for (const [name, { data, options }] of this.files) {
100
- filesObj[name] = options ? [data, options] : data;
101
- }
102
-
103
- // Use sync version for Deno compatibility (fflate async uses Web Workers)
104
- try {
105
- const result = plugins.fflate.zipSync(filesObj);
106
- this.push(Buffer.from(result));
107
- this.push(null);
108
- } catch (err) {
109
- throw err;
110
- }
111
- }
112
-
113
- _read(): void {
114
- // No-op: data is pushed when finalize() is called
115
- }
116
-
117
- _write(
118
- _chunk: Buffer,
119
- _encoding: BufferEncoding,
120
- callback: (error?: Error | null) => void
121
- ): void {
122
- // Not used for ZIP creation - use addEntry() instead
123
- callback(new Error('Use addEntry() to add files to the ZIP archive'));
124
- }
125
- }
126
-
127
- /**
128
- * ZIP compression and decompression utilities
129
- */
130
- export class ZipTools {
131
- /**
132
- * Get a streaming compression object for creating ZIP archives
133
- */
134
- public getCompressionStream(): ZipCompressionStream {
135
- return new ZipCompressionStream();
136
- }
137
-
138
- /**
139
- * Get a streaming decompression transform for extracting ZIP archives
140
- */
141
- public getDecompressionStream(): ZipDecompressionTransform {
142
- return new ZipDecompressionTransform();
143
- }
144
-
145
- /**
146
- * Create a ZIP archive from an array of entries
147
- */
148
- public async createZip(entries: IArchiveEntry[], compressionLevel?: TCompressionLevel): Promise<Buffer> {
149
- const filesObj: plugins.fflate.Zippable = {};
150
-
151
- for (const entry of entries) {
152
- let data: Uint8Array;
153
-
154
- if (typeof entry.content === 'string') {
155
- data = new TextEncoder().encode(entry.content);
156
- } else if (Buffer.isBuffer(entry.content)) {
157
- data = new Uint8Array(entry.content);
158
- } else if (entry.content instanceof plugins.smartfile.SmartFile) {
159
- data = new Uint8Array(entry.content.contents);
160
- } else if (entry.content instanceof plugins.smartfile.StreamFile) {
161
- const buffer = await entry.content.getContentAsBuffer();
162
- data = new Uint8Array(buffer);
163
- } else {
164
- // Readable stream
165
- const chunks: Buffer[] = [];
166
- for await (const chunk of entry.content as plugins.stream.Readable) {
167
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
168
- }
169
- data = new Uint8Array(Buffer.concat(chunks));
170
- }
171
-
172
- if (compressionLevel !== undefined) {
173
- filesObj[entry.archivePath] = [data, { level: compressionLevel }];
174
- } else {
175
- filesObj[entry.archivePath] = data;
176
- }
177
- }
178
-
179
- // Use sync version for Deno compatibility (fflate async uses Web Workers)
180
- const result = plugins.fflate.zipSync(filesObj);
181
- return Buffer.from(result);
182
- }
183
-
184
- /**
185
- * Extract a ZIP buffer to an array of entries
186
- */
187
- public async extractZip(data: Buffer): Promise<Array<{ path: string; content: Buffer }>> {
188
- // Use sync version for Deno compatibility (fflate async uses Web Workers)
189
- const result = plugins.fflate.unzipSync(data);
190
- const entries: Array<{ path: string; content: Buffer }> = [];
191
- for (const [path, content] of Object.entries(result)) {
192
- entries.push({ path, content: Buffer.from(content) });
193
- }
194
- return entries;
195
- }
196
- }
File without changes
File without changes