@push.rocks/smartarchive 4.2.4 → 5.0.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 (37) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/bzip2/bititerator.d.ts +6 -1
  3. package/dist_ts/bzip2/bititerator.js +30 -24
  4. package/dist_ts/bzip2/bzip2.d.ts +27 -12
  5. package/dist_ts/bzip2/bzip2.js +325 -263
  6. package/dist_ts/bzip2/index.d.ts +4 -1
  7. package/dist_ts/bzip2/index.js +36 -38
  8. package/dist_ts/classes.archiveanalyzer.d.ts +25 -5
  9. package/dist_ts/classes.archiveanalyzer.js +19 -8
  10. package/dist_ts/classes.bzip2tools.d.ts +1 -1
  11. package/dist_ts/classes.gziptools.d.ts +39 -6
  12. package/dist_ts/classes.gziptools.js +85 -24
  13. package/dist_ts/classes.smartarchive.d.ts +101 -16
  14. package/dist_ts/classes.smartarchive.js +395 -58
  15. package/dist_ts/classes.tartools.d.ts +31 -4
  16. package/dist_ts/classes.tartools.js +93 -32
  17. package/dist_ts/classes.ziptools.d.ts +47 -12
  18. package/dist_ts/classes.ziptools.js +142 -23
  19. package/dist_ts/errors.d.ts +44 -0
  20. package/dist_ts/errors.js +62 -0
  21. package/dist_ts/index.d.ts +4 -0
  22. package/dist_ts/index.js +9 -1
  23. package/dist_ts/interfaces.d.ts +115 -0
  24. package/dist_ts/interfaces.js +2 -0
  25. package/package.json +1 -1
  26. package/ts/00_commitinfo_data.ts +1 -1
  27. package/ts/bzip2/bititerator.ts +43 -27
  28. package/ts/bzip2/bzip2.ts +289 -171
  29. package/ts/bzip2/index.ts +52 -50
  30. package/ts/classes.archiveanalyzer.ts +42 -28
  31. package/ts/classes.gziptools.ts +96 -33
  32. package/ts/classes.smartarchive.ts +469 -118
  33. package/ts/classes.tartools.ts +124 -52
  34. package/ts/classes.ziptools.ts +160 -34
  35. package/ts/errors.ts +70 -0
  36. package/ts/index.ts +11 -0
  37. package/ts/interfaces.ts +131 -0
@@ -0,0 +1,115 @@
1
+ import type * as stream from 'node:stream';
2
+ import type { SmartFile, StreamFile } from '@push.rocks/smartfile';
3
+ /**
4
+ * Supported archive formats
5
+ */
6
+ export type TArchiveFormat = 'tar' | 'tar.gz' | 'tgz' | 'zip' | 'gz' | 'bz2';
7
+ /**
8
+ * Compression level (0 = no compression, 9 = maximum compression)
9
+ */
10
+ export type TCompressionLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
11
+ /**
12
+ * Supported MIME types for archive detection
13
+ */
14
+ export type TSupportedMime = 'application/gzip' | 'application/zip' | 'application/x-bzip2' | 'application/x-tar' | undefined;
15
+ /**
16
+ * Entry to add to an archive during creation
17
+ */
18
+ export interface IArchiveEntry {
19
+ /** Path within the archive */
20
+ archivePath: string;
21
+ /** Content: string, Buffer, Readable stream, SmartFile, or StreamFile */
22
+ content: string | Buffer | stream.Readable | SmartFile | StreamFile;
23
+ /** Optional size hint for streams (improves performance) */
24
+ size?: number;
25
+ /** Optional file mode/permissions */
26
+ mode?: number;
27
+ /** Optional modification time */
28
+ mtime?: Date;
29
+ }
30
+ /**
31
+ * Options for creating archives
32
+ */
33
+ export interface IArchiveCreationOptions {
34
+ /** Target archive format */
35
+ format: TArchiveFormat;
36
+ /** Compression level (0-9, default depends on format) */
37
+ compressionLevel?: TCompressionLevel;
38
+ /** Base path to strip from file paths in archive */
39
+ basePath?: string;
40
+ }
41
+ /**
42
+ * Options for extracting archives
43
+ */
44
+ export interface IArchiveExtractionOptions {
45
+ /** Target directory for extraction */
46
+ targetDir: string;
47
+ /** Optional filename for single-file archives (gz, bz2) */
48
+ fileName?: string;
49
+ /** Number of leading path components to strip */
50
+ stripComponents?: number;
51
+ /** Filter function to select which entries to extract */
52
+ filter?: (entry: IArchiveEntryInfo) => boolean;
53
+ /** Whether to overwrite existing files */
54
+ overwrite?: boolean;
55
+ }
56
+ /**
57
+ * Information about an archive entry
58
+ */
59
+ export interface IArchiveEntryInfo {
60
+ /** Path of the entry within the archive */
61
+ path: string;
62
+ /** Size in bytes */
63
+ size: number;
64
+ /** Whether this entry is a directory */
65
+ isDirectory: boolean;
66
+ /** Whether this entry is a file */
67
+ isFile: boolean;
68
+ /** Modification time */
69
+ mtime?: Date;
70
+ /** File mode/permissions */
71
+ mode?: number;
72
+ }
73
+ /**
74
+ * Result of archive analysis
75
+ */
76
+ export interface IArchiveInfo {
77
+ /** Detected archive format */
78
+ format: TArchiveFormat | null;
79
+ /** Whether the archive is compressed */
80
+ isCompressed: boolean;
81
+ /** Whether this is a recognized archive format */
82
+ isArchive: boolean;
83
+ /** List of entries (if available without full extraction) */
84
+ entries?: IArchiveEntryInfo[];
85
+ }
86
+ /**
87
+ * Options for adding a file to a TAR pack stream
88
+ */
89
+ export interface IAddFileOptions {
90
+ /** Filename within the archive */
91
+ fileName?: string;
92
+ /** File content */
93
+ content?: string | Buffer | stream.Readable | SmartFile | StreamFile;
94
+ /** Size in bytes (required for streams) */
95
+ byteLength?: number;
96
+ /** Path to file on disk (alternative to content) */
97
+ filePath?: string;
98
+ }
99
+ /**
100
+ * Bit reader interface for BZIP2 decompression
101
+ */
102
+ export interface IBitReader {
103
+ (n: number | null): number | void;
104
+ bytesRead: number;
105
+ }
106
+ /**
107
+ * Huffman group for BZIP2 decompression
108
+ */
109
+ export interface IHuffmanGroup {
110
+ permute: Int32Array;
111
+ limit: Int32Array;
112
+ base: Int32Array;
113
+ minLen: number;
114
+ maxLen: number;
115
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2ludGVyZmFjZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push.rocks/smartarchive",
3
- "version": "4.2.4",
3
+ "version": "5.0.0",
4
4
  "description": "A library for working with archive files, providing utilities for compressing and decompressing data.",
5
5
  "main": "dist_ts/index.js",
6
6
  "typings": "dist_ts/index.d.ts",
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartarchive',
6
- version: '4.2.4',
6
+ version: '5.0.0',
7
7
  description: 'A library for working with archive files, providing utilities for compressing and decompressing data.'
8
8
  }
@@ -1,44 +1,60 @@
1
- var BITMASK = [0, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff];
2
-
3
- // returns a function that reads bits.
4
- // takes a buffer iterator as input
5
- export function bitIterator(nextBuffer: () => Buffer) {
6
- var bit = 0,
7
- byte = 0;
8
- var bytes = nextBuffer();
9
- var f = function (n) {
10
- if (n === null && bit != 0) {
1
+ import type { IBitReader } from '../interfaces.js';
2
+
3
+ const BITMASK = [0, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff] as const;
4
+
5
+ /**
6
+ * Creates a bit reader function for BZIP2 decompression.
7
+ * Takes a buffer iterator as input and returns a function that reads bits.
8
+ */
9
+ export function bitIterator(nextBuffer: () => Buffer): IBitReader {
10
+ let bit = 0;
11
+ let byte = 0;
12
+ let bytes = nextBuffer();
13
+ let _bytesRead = 0;
14
+
15
+ const reader = function (n: number | null): number | void {
16
+ if (n === null && bit !== 0) {
11
17
  // align to byte boundary
12
18
  bit = 0;
13
19
  byte++;
14
20
  return;
15
21
  }
16
- var result = 0;
17
- while (n > 0) {
22
+
23
+ let result = 0;
24
+ let remaining = n as number;
25
+
26
+ while (remaining > 0) {
18
27
  if (byte >= bytes.length) {
19
28
  byte = 0;
20
29
  bytes = nextBuffer();
21
30
  }
22
- var left = 8 - bit;
23
- if (bit === 0 && n > 0)
24
- // @ts-ignore
25
- f.bytesRead++;
26
- if (n >= left) {
31
+
32
+ const left = 8 - bit;
33
+
34
+ if (bit === 0 && remaining > 0) {
35
+ _bytesRead++;
36
+ }
37
+
38
+ if (remaining >= left) {
27
39
  result <<= left;
28
40
  result |= BITMASK[left] & bytes[byte++];
29
41
  bit = 0;
30
- n -= left;
42
+ remaining -= left;
31
43
  } else {
32
- result <<= n;
33
- result |=
34
- (bytes[byte] & (BITMASK[n] << (8 - n - bit))) >> (8 - n - bit);
35
- bit += n;
36
- n = 0;
44
+ result <<= remaining;
45
+ result |= (bytes[byte] & (BITMASK[remaining] << (8 - remaining - bit))) >> (8 - remaining - bit);
46
+ bit += remaining;
47
+ remaining = 0;
37
48
  }
38
49
  }
50
+
39
51
  return result;
40
- };
41
- // @ts-ignore
42
- f.bytesRead = 0;
43
- return f;
52
+ } as IBitReader;
53
+
54
+ Object.defineProperty(reader, 'bytesRead', {
55
+ get: () => _bytesRead,
56
+ enumerable: true,
57
+ });
58
+
59
+ return reader;
44
60
  }