@push.rocks/smartarchive 4.2.3 → 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 +398 -61
- package/dist_ts/classes.tartools.d.ts +31 -4
- package/dist_ts/classes.tartools.js +97 -36
- 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/dist_ts/plugins.d.ts +9 -3
- package/dist_ts/plugins.js +27 -4
- package/package.json +3 -4
- package/readme.hints.md +38 -1
- package/readme.md +248 -137
- 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 +472 -122
- package/ts/classes.tartools.ts +128 -59
- 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
- package/ts/plugins.ts +29 -3
package/ts/interfaces.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type * as stream from 'node:stream';
|
|
2
|
+
import type { SmartFile, StreamFile } from '@push.rocks/smartfile';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Supported archive formats
|
|
6
|
+
*/
|
|
7
|
+
export type TArchiveFormat = 'tar' | 'tar.gz' | 'tgz' | 'zip' | 'gz' | 'bz2';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Compression level (0 = no compression, 9 = maximum compression)
|
|
11
|
+
*/
|
|
12
|
+
export type TCompressionLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Supported MIME types for archive detection
|
|
16
|
+
*/
|
|
17
|
+
export type TSupportedMime =
|
|
18
|
+
| 'application/gzip'
|
|
19
|
+
| 'application/zip'
|
|
20
|
+
| 'application/x-bzip2'
|
|
21
|
+
| 'application/x-tar'
|
|
22
|
+
| undefined;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Entry to add to an archive during creation
|
|
26
|
+
*/
|
|
27
|
+
export interface IArchiveEntry {
|
|
28
|
+
/** Path within the archive */
|
|
29
|
+
archivePath: string;
|
|
30
|
+
/** Content: string, Buffer, Readable stream, SmartFile, or StreamFile */
|
|
31
|
+
content: string | Buffer | stream.Readable | SmartFile | StreamFile;
|
|
32
|
+
/** Optional size hint for streams (improves performance) */
|
|
33
|
+
size?: number;
|
|
34
|
+
/** Optional file mode/permissions */
|
|
35
|
+
mode?: number;
|
|
36
|
+
/** Optional modification time */
|
|
37
|
+
mtime?: Date;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Options for creating archives
|
|
42
|
+
*/
|
|
43
|
+
export interface IArchiveCreationOptions {
|
|
44
|
+
/** Target archive format */
|
|
45
|
+
format: TArchiveFormat;
|
|
46
|
+
/** Compression level (0-9, default depends on format) */
|
|
47
|
+
compressionLevel?: TCompressionLevel;
|
|
48
|
+
/** Base path to strip from file paths in archive */
|
|
49
|
+
basePath?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Options for extracting archives
|
|
54
|
+
*/
|
|
55
|
+
export interface IArchiveExtractionOptions {
|
|
56
|
+
/** Target directory for extraction */
|
|
57
|
+
targetDir: string;
|
|
58
|
+
/** Optional filename for single-file archives (gz, bz2) */
|
|
59
|
+
fileName?: string;
|
|
60
|
+
/** Number of leading path components to strip */
|
|
61
|
+
stripComponents?: number;
|
|
62
|
+
/** Filter function to select which entries to extract */
|
|
63
|
+
filter?: (entry: IArchiveEntryInfo) => boolean;
|
|
64
|
+
/** Whether to overwrite existing files */
|
|
65
|
+
overwrite?: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Information about an archive entry
|
|
70
|
+
*/
|
|
71
|
+
export interface IArchiveEntryInfo {
|
|
72
|
+
/** Path of the entry within the archive */
|
|
73
|
+
path: string;
|
|
74
|
+
/** Size in bytes */
|
|
75
|
+
size: number;
|
|
76
|
+
/** Whether this entry is a directory */
|
|
77
|
+
isDirectory: boolean;
|
|
78
|
+
/** Whether this entry is a file */
|
|
79
|
+
isFile: boolean;
|
|
80
|
+
/** Modification time */
|
|
81
|
+
mtime?: Date;
|
|
82
|
+
/** File mode/permissions */
|
|
83
|
+
mode?: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Result of archive analysis
|
|
88
|
+
*/
|
|
89
|
+
export interface IArchiveInfo {
|
|
90
|
+
/** Detected archive format */
|
|
91
|
+
format: TArchiveFormat | null;
|
|
92
|
+
/** Whether the archive is compressed */
|
|
93
|
+
isCompressed: boolean;
|
|
94
|
+
/** Whether this is a recognized archive format */
|
|
95
|
+
isArchive: boolean;
|
|
96
|
+
/** List of entries (if available without full extraction) */
|
|
97
|
+
entries?: IArchiveEntryInfo[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Options for adding a file to a TAR pack stream
|
|
102
|
+
*/
|
|
103
|
+
export interface IAddFileOptions {
|
|
104
|
+
/** Filename within the archive */
|
|
105
|
+
fileName?: string;
|
|
106
|
+
/** File content */
|
|
107
|
+
content?: string | Buffer | stream.Readable | SmartFile | StreamFile;
|
|
108
|
+
/** Size in bytes (required for streams) */
|
|
109
|
+
byteLength?: number;
|
|
110
|
+
/** Path to file on disk (alternative to content) */
|
|
111
|
+
filePath?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Bit reader interface for BZIP2 decompression
|
|
116
|
+
*/
|
|
117
|
+
export interface IBitReader {
|
|
118
|
+
(n: number | null): number | void;
|
|
119
|
+
bytesRead: number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Huffman group for BZIP2 decompression
|
|
124
|
+
*/
|
|
125
|
+
export interface IHuffmanGroup {
|
|
126
|
+
permute: Int32Array;
|
|
127
|
+
limit: Int32Array;
|
|
128
|
+
base: Int32Array;
|
|
129
|
+
minLen: number;
|
|
130
|
+
maxLen: number;
|
|
131
|
+
}
|
package/ts/plugins.ts
CHANGED
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
// node native scope
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import * as stream from 'stream';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as stream from 'node:stream';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as fsPromises from 'node:fs/promises';
|
|
4
6
|
|
|
5
|
-
export { path, stream };
|
|
7
|
+
export { path, stream, fs, fsPromises };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* List files in a directory recursively, returning relative paths
|
|
11
|
+
*/
|
|
12
|
+
export async function listFileTree(dirPath: string, _pattern: string = '**/*'): Promise<string[]> {
|
|
13
|
+
const results: string[] = [];
|
|
14
|
+
|
|
15
|
+
async function walkDir(currentPath: string, relativePath: string = '') {
|
|
16
|
+
const entries = await fsPromises.readdir(currentPath, { withFileTypes: true });
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const entryRelPath = relativePath ? path.join(relativePath, entry.name) : entry.name;
|
|
19
|
+
const entryFullPath = path.join(currentPath, entry.name);
|
|
20
|
+
|
|
21
|
+
if (entry.isDirectory()) {
|
|
22
|
+
await walkDir(entryFullPath, entryRelPath);
|
|
23
|
+
} else if (entry.isFile()) {
|
|
24
|
+
results.push(entryRelPath);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await walkDir(dirPath);
|
|
30
|
+
return results;
|
|
31
|
+
}
|
|
6
32
|
|
|
7
33
|
// @pushrocks scope
|
|
8
34
|
import * as smartfile from '@push.rocks/smartfile';
|