@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.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/bzip2/bititerator.d.ts +6 -1
- package/dist_ts/bzip2/bititerator.js +30 -24
- package/dist_ts/bzip2/bzip2.d.ts +27 -12
- package/dist_ts/bzip2/bzip2.js +325 -263
- package/dist_ts/bzip2/index.d.ts +4 -1
- package/dist_ts/bzip2/index.js +36 -38
- package/dist_ts/classes.archiveanalyzer.d.ts +25 -5
- package/dist_ts/classes.archiveanalyzer.js +19 -8
- package/dist_ts/classes.bzip2tools.d.ts +1 -1
- package/dist_ts/classes.gziptools.d.ts +39 -6
- package/dist_ts/classes.gziptools.js +85 -24
- package/dist_ts/classes.smartarchive.d.ts +101 -16
- package/dist_ts/classes.smartarchive.js +395 -58
- package/dist_ts/classes.tartools.d.ts +31 -4
- package/dist_ts/classes.tartools.js +93 -32
- package/dist_ts/classes.ziptools.d.ts +47 -12
- package/dist_ts/classes.ziptools.js +142 -23
- package/dist_ts/errors.d.ts +44 -0
- package/dist_ts/errors.js +62 -0
- package/dist_ts/index.d.ts +4 -0
- package/dist_ts/index.js +9 -1
- package/dist_ts/interfaces.d.ts +115 -0
- package/dist_ts/interfaces.js +2 -0
- package/package.json +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/bzip2/bititerator.ts +43 -27
- package/ts/bzip2/bzip2.ts +289 -171
- package/ts/bzip2/index.ts +52 -50
- package/ts/classes.archiveanalyzer.ts +42 -28
- package/ts/classes.gziptools.ts +96 -33
- package/ts/classes.smartarchive.ts +469 -118
- package/ts/classes.tartools.ts +124 -52
- package/ts/classes.ziptools.ts +160 -34
- package/ts/errors.ts +70 -0
- package/ts/index.ts +11 -0
- 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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartarchive",
|
|
3
|
-
"version": "
|
|
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",
|
package/ts/00_commitinfo_data.ts
CHANGED
package/ts/bzip2/bititerator.ts
CHANGED
|
@@ -1,44 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
42
|
+
remaining -= left;
|
|
31
43
|
} else {
|
|
32
|
-
result <<=
|
|
33
|
-
result |=
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
} as IBitReader;
|
|
53
|
+
|
|
54
|
+
Object.defineProperty(reader, 'bytesRead', {
|
|
55
|
+
get: () => _bytesRead,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return reader;
|
|
44
60
|
}
|