@push.rocks/smartarchive 4.2.4 → 5.0.1

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 (39) 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 +43 -6
  12. package/dist_ts/classes.gziptools.js +76 -24
  13. package/dist_ts/classes.smartarchive.d.ts +198 -16
  14. package/dist_ts/classes.smartarchive.js +652 -79
  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 +128 -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 +119 -0
  24. package/dist_ts/interfaces.js +2 -0
  25. package/package.json +1 -1
  26. package/readme.hints.md +69 -23
  27. package/readme.md +360 -274
  28. package/ts/00_commitinfo_data.ts +1 -1
  29. package/ts/bzip2/bititerator.ts +43 -27
  30. package/ts/bzip2/bzip2.ts +289 -171
  31. package/ts/bzip2/index.ts +52 -50
  32. package/ts/classes.archiveanalyzer.ts +42 -28
  33. package/ts/classes.gziptools.ts +91 -33
  34. package/ts/classes.smartarchive.ts +765 -140
  35. package/ts/classes.tartools.ts +124 -52
  36. package/ts/classes.ziptools.ts +147 -34
  37. package/ts/errors.ts +70 -0
  38. package/ts/index.ts +11 -0
  39. package/ts/interfaces.ts +136 -0
package/dist_ts/index.js CHANGED
@@ -1,5 +1,13 @@
1
+ // Core types and errors
2
+ export * from './interfaces.js';
3
+ export * from './errors.js';
4
+ // Main archive class
1
5
  export * from './classes.smartarchive.js';
6
+ // Format-specific tools
2
7
  export * from './classes.tartools.js';
3
8
  export * from './classes.ziptools.js';
4
9
  export * from './classes.gziptools.js';
5
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLDJCQUEyQixDQUFDO0FBQzFDLGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyx1QkFBdUIsQ0FBQztBQUN0QyxjQUFjLHdCQUF3QixDQUFDIn0=
10
+ export * from './classes.bzip2tools.js';
11
+ // Archive analysis
12
+ export * from './classes.archiveanalyzer.js';
13
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSx3QkFBd0I7QUFDeEIsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxjQUFjLGFBQWEsQ0FBQztBQUU1QixxQkFBcUI7QUFDckIsY0FBYywyQkFBMkIsQ0FBQztBQUUxQyx3QkFBd0I7QUFDeEIsY0FBYyx1QkFBdUIsQ0FBQztBQUN0QyxjQUFjLHVCQUF1QixDQUFDO0FBQ3RDLGNBQWMsd0JBQXdCLENBQUM7QUFDdkMsY0FBYyx5QkFBeUIsQ0FBQztBQUV4QyxtQkFBbUI7QUFDbkIsY0FBYyw4QkFBOEIsQ0FBQyJ9
@@ -0,0 +1,119 @@
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
+ }
116
+ /**
117
+ * Entry filter predicate for fluent API
118
+ */
119
+ export type TEntryFilter = (entry: IArchiveEntryInfo) => boolean;
@@ -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.1",
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/readme.hints.md CHANGED
@@ -1,38 +1,84 @@
1
1
  # Smartarchive Development Hints
2
2
 
3
- ## Dependency Upgrades (2025-01-25)
3
+ ## Architecture Overview
4
4
 
5
- ### Completed Upgrades
6
- - **@git.zone/tsbuild**: ^2.6.6 → ^3.1.0
7
- - **@git.zone/tsrun**: ^1.3.3 → ^2.0.0
8
- - **@git.zone/tstest**: ^2.3.4 → ^3.1.3
9
- - **@push.rocks/smartfile**: ^11.2.7 → ^13.0.0
5
+ `@push.rocks/smartarchive` uses a **fluent builder pattern** for all archive operations. The main entry point is `SmartArchive.create()` which returns a builder instance.
10
6
 
11
- ### Migration Notes
7
+ ### Two Operating Modes
12
8
 
13
- #### Smartfile v13 Migration
14
- Smartfile v13 removed filesystem operations (`fs`, `memory`, `fsStream` namespaces). These were replaced with Node.js native `fs` and `fs/promises`:
9
+ 1. **Extraction Mode** - Triggered by `.url()`, `.file()`, `.stream()`, or `.buffer()`
10
+ 2. **Creation Mode** - Triggered by `.format()` or `.entry()`
15
11
 
16
- **Replacements made:**
12
+ Modes are mutually exclusive - you cannot mix extraction and creation methods in the same chain.
13
+
14
+ ## Key Classes
15
+
16
+ - **SmartArchive** - Main class with fluent API for all operations
17
+ - **TarTools** - TAR-specific operations (pack/extract)
18
+ - **ZipTools** - ZIP-specific operations using fflate
19
+ - **GzipTools** - GZIP compression/decompression using fflate
20
+ - **Bzip2Tools** - BZIP2 decompression (extract only, no creation)
21
+ - **ArchiveAnalyzer** - Format detection via magic bytes
22
+
23
+ ## Dependencies
24
+
25
+ - **fflate** - Pure JS compression for ZIP/GZIP (works in browser)
26
+ - **tar-stream** - TAR archive handling
27
+ - **file-type** - MIME type detection via magic bytes
28
+ - **@push.rocks/smartfile** - SmartFile and StreamFile classes
29
+
30
+ ## API Changes (v5.0.0)
31
+
32
+ The v5.0.0 release introduced a complete API refactor:
33
+
34
+ ### Old API (deprecated)
35
+ ```typescript
36
+ // Old static factory methods - NO LONGER EXIST
37
+ await SmartArchive.fromUrl(url);
38
+ await SmartArchive.fromFile(path);
39
+ await SmartArchive.fromDirectory(path, options);
40
+ ```
41
+
42
+ ### New Fluent API
43
+ ```typescript
44
+ // Current fluent builder pattern
45
+ await SmartArchive.create()
46
+ .url(url)
47
+ .extract(targetDir);
48
+
49
+ await SmartArchive.create()
50
+ .format('tar.gz')
51
+ .directory(path)
52
+ .toFile(outputPath);
53
+ ```
54
+
55
+ ## Migration Notes (from v4.x)
56
+
57
+ ### Smartfile v13 Changes
58
+ Smartfile v13 removed filesystem operations. Replacements:
17
59
  - `smartfile.fs.ensureDir(path)` → `fsPromises.mkdir(path, { recursive: true })`
18
60
  - `smartfile.fs.stat(path)` → `fsPromises.stat(path)`
19
61
  - `smartfile.fs.toReadStream(path)` → `fs.createReadStream(path)`
20
- - `smartfile.fs.toStringSync(path)` → `fsPromises.readFile(path, 'utf8')`
21
- - `smartfile.fs.listFileTree(dir, pattern)` → custom `listFileTree()` helper
22
- - `smartfile.fsStream.createReadStream(path)` → `fs.createReadStream(path)`
23
- - `smartfile.fsStream.createWriteStream(path)` → `fs.createWriteStream(path)`
24
- - `smartfile.memory.toFs(content, path)` → `fsPromises.writeFile(path, content)`
25
62
 
26
- **Still using from smartfile v13:**
63
+ ### Still using from smartfile
27
64
  - `SmartFile` class (in-memory file representation)
28
65
  - `StreamFile` class (streaming file handling)
29
66
 
30
- ### Removed Dependencies
31
- - `through@2.3.8` - was unused in the codebase
67
+ ## Testing
68
+
69
+ ```bash
70
+ pnpm test # Run all tests
71
+ tstest test/test.node+deno.ts --verbose # Run specific test
72
+ ```
73
+
74
+ Tests use a Verdaccio registry URL (`verdaccio.lossless.digital`) for test archives.
32
75
 
33
- ## Architecture Notes
76
+ ## Key Files
34
77
 
35
- - Uses `fflate` for ZIP/GZIP compression (pure JS, works in browser)
36
- - Uses `tar-stream` for TAR archive handling
37
- - Uses `file-type` for MIME type detection
38
- - Custom BZIP2 implementation in `ts/bzip2/` directory
78
+ - `ts/classes.smartarchive.ts` - Main SmartArchive class with fluent API
79
+ - `ts/classes.tartools.ts` - TAR operations
80
+ - `ts/classes.ziptools.ts` - ZIP operations
81
+ - `ts/classes.gziptools.ts` - GZIP operations
82
+ - `ts/classes.bzip2tools.ts` - BZIP2 decompression
83
+ - `ts/classes.archiveanalyzer.ts` - Format detection
84
+ - `ts/interfaces.ts` - Type definitions