tar-vern 0.1.0 → 0.3.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/README.md +98 -105
- package/README_pack.md +16 -28
- package/dist/generated/packageMetadata.d.ts +2 -2
- package/dist/index.cjs +211 -147
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +211 -147
- package/dist/index.js.map +1 -1
- package/dist/packer.d.ts +1 -1
- package/dist/packer.d.ts.map +1 -1
- package/dist/types.d.ts +6 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +26 -4
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
@@ -18,13 +18,44 @@ graph LR
|
|
18
18
|
B --> C[TAR File<br/>'foobar.tar']
|
19
19
|
```
|
20
20
|
|
21
|
+
## Packing minimum example
|
22
|
+
|
23
|
+
tar-vern supplies file and directory information to pack through "TypeScript async generator."
|
24
|
+
This allows you to specify pack data with very concise code.
|
25
|
+
|
26
|
+
```typescript
|
27
|
+
import {
|
28
|
+
createTarPacker, storeReaderToFile,
|
29
|
+
createFileItem, createDirectoryItem } from 'tar-vern';
|
30
|
+
|
31
|
+
// Create an async generator for tar entries
|
32
|
+
const itemGenerator = async function*() {
|
33
|
+
// Add a simple text file
|
34
|
+
yield await createFileItem(
|
35
|
+
'hello.txt', // file name
|
36
|
+
'Hello, world!' // text contents
|
37
|
+
);
|
38
|
+
|
39
|
+
// Add a directory
|
40
|
+
yield await createDirectoryItem('mydir');
|
41
|
+
|
42
|
+
// (Make your own entries with yield expression...)
|
43
|
+
};
|
44
|
+
|
45
|
+
// Create tar stream and write to file
|
46
|
+
const packer = createTarPacker(itemGenerator());
|
47
|
+
await storeReaderToFile(packer, 'archive.tar.gz'); // Use helper to awaitable
|
48
|
+
```
|
49
|
+
|
21
50
|
## Features
|
22
51
|
|
23
52
|
- Streaming API: Memory-efficient processing of large files
|
24
53
|
- Multiple content sources: String, Buffer, ReadableStream, file paths and async generators
|
25
54
|
- Metadata preservation: File permissions, ownership, timestamps
|
26
55
|
- Built-in compression: GZip compression support (`tar.gz` format)
|
27
|
-
- No
|
56
|
+
- No external dependencies.
|
57
|
+
|
58
|
+
----
|
28
59
|
|
29
60
|
## Installation
|
30
61
|
|
@@ -32,18 +63,19 @@ graph LR
|
|
32
63
|
npm install tar-vern
|
33
64
|
```
|
34
65
|
|
35
|
-
----
|
36
|
-
|
37
66
|
## Usage for tar packing
|
38
67
|
|
39
|
-
###
|
68
|
+
### EntryItem basis
|
40
69
|
|
41
|
-
|
42
|
-
|
70
|
+
The async generator needs to produce `EntryItem` objects.
|
71
|
+
These objects hold information about files and directories to be stored in the tar archive, and for files, they also contain content data information.
|
72
|
+
|
73
|
+
There are no special requirements for this information, so you can construct everything manually:
|
43
74
|
|
75
|
+
```typescript
|
44
76
|
// Create an async generator for tar entries
|
45
|
-
const
|
46
|
-
//
|
77
|
+
const itemGenerator = async function*() {
|
78
|
+
// Construct a simple text file item
|
47
79
|
yield {
|
48
80
|
kind: 'file',
|
49
81
|
path: 'hello.txt',
|
@@ -54,9 +86,9 @@ const generator = async function*() {
|
|
54
86
|
gid: 1000,
|
55
87
|
date: new Date(),
|
56
88
|
content: 'Hello, world!' // text contents
|
57
|
-
};
|
89
|
+
} as EntryItem;
|
58
90
|
|
59
|
-
//
|
91
|
+
// Construct a directory item
|
60
92
|
yield {
|
61
93
|
kind: 'directory',
|
62
94
|
path: 'mydir',
|
@@ -66,58 +98,34 @@ const generator = async function*() {
|
|
66
98
|
uid: 1000,
|
67
99
|
gid: 1000,
|
68
100
|
date: new Date()
|
69
|
-
};
|
101
|
+
} as EntryItem;
|
70
102
|
};
|
71
|
-
|
72
|
-
// Create tar stream and write to file
|
73
|
-
const packer = createTarPacker(generator());
|
74
|
-
await storeReaderToFile(packer, 'archive.tar'); // Use helper to awaitable
|
75
103
|
```
|
76
104
|
|
77
|
-
|
105
|
+
However, constructing all `EntryItem` objects manually can be tedious. Therefore, helper functions are provided as follows.
|
78
106
|
|
79
|
-
|
80
|
-
|
81
|
-
|`CompressionTypes`|Details|
|
82
|
-
|:----|:----|
|
83
|
-
|`none`|Uncompression (default)|
|
84
|
-
|`gzip`|Combined GZip compression stream|
|
107
|
+
### Helper functions
|
85
108
|
|
86
|
-
|
87
|
-
import { createTarPacker, storeReaderToFile, CompressionTypes } from 'tar-vern';
|
109
|
+
Helper functions are provided to simplify the construction of `EntryItem` objects. The following types are available:
|
88
110
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
uid: 1000,
|
97
|
-
gid: 1000,
|
98
|
-
date: new Date(),
|
99
|
-
content: 'Large amount of data...'
|
100
|
-
};
|
101
|
-
};
|
102
|
-
|
103
|
-
// Create compressed tar stream
|
104
|
-
const packer = createTarPacker(generator(), 'gzip');
|
105
|
-
await storeReaderToFile(packer, 'archive.tar.gz');
|
106
|
-
```
|
111
|
+
|Function|Details|
|
112
|
+
|:----|:----|
|
113
|
+
|`createDirectoryItem()`|Construct directory item|
|
114
|
+
|`createFileItem()`|Construct basic file item from string or `Buffer`|
|
115
|
+
|`createReadableFileItem()`|Construct file item from readable stream (`stream.Readable`)|
|
116
|
+
|`createGeneratorFileItem()`|Construct file item from async generator|
|
117
|
+
|`createReadFileItem()`|Construct file item from a file on real filesystem|
|
107
118
|
|
108
|
-
|
119
|
+
For example:
|
109
120
|
|
110
121
|
```typescript
|
111
|
-
import {
|
112
|
-
createReadFileItem,
|
113
|
-
createDirectoryItem,
|
114
|
-
createReadableItem,
|
115
|
-
storeReaderToFile
|
116
|
-
} from 'tar-vern';
|
117
122
|
import { createReadStream } from 'fs';
|
123
|
+
import {
|
124
|
+
createReadFileItem, createDirectoryItem,
|
125
|
+
createReadableFileItem, storeReaderToFile } from 'tar-vern';
|
118
126
|
|
119
127
|
// Configuration easier with item creation functions
|
120
|
-
const
|
128
|
+
const itemGenerator = async function*() {
|
121
129
|
// Add file from filesystem (auto-detects metadata)
|
122
130
|
yield await createReadFileItem('archived-name.txt', '/path/to/real/source.txt');
|
123
131
|
|
@@ -127,85 +135,70 @@ const generator = async function*() {
|
|
127
135
|
});
|
128
136
|
|
129
137
|
// Add from readable stream
|
130
|
-
const stream = createReadStream('/path/to/large-file.bin');
|
131
|
-
yield await
|
138
|
+
const stream = createReadStream('/path/to/real/large-file.bin');
|
139
|
+
yield await createReadableFileItem('large-file.bin', stream);
|
132
140
|
};
|
133
141
|
|
134
142
|
// The `packer` generally `stream.Readable`
|
135
|
-
const packer = createTarPacker(
|
143
|
+
const packer = createTarPacker(itemGenerator());
|
136
144
|
|
137
145
|
// Safer awaitable store file from `stream.Readable`
|
138
146
|
await storeReaderToFile(packer, 'output.tar');
|
139
147
|
```
|
140
148
|
|
141
|
-
|
142
|
-
|
143
|
-
```typescript
|
144
|
-
const generator = async function*() {
|
145
|
-
// String content
|
146
|
-
yield {
|
147
|
-
kind: 'file',
|
148
|
-
path: 'text.txt',
|
149
|
-
content: 'Text content' // Store with utf8 encoding
|
150
|
-
// ... other properties
|
151
|
-
};
|
152
|
-
|
153
|
-
// Buffer content
|
154
|
-
yield {
|
155
|
-
kind: 'file',
|
156
|
-
path: 'binary.bin',
|
157
|
-
content: Buffer.from([0x48, 0x65, 0x6c, 0x6c, 0x6f])
|
158
|
-
// ... other properties
|
159
|
-
};
|
160
|
-
|
161
|
-
// Readable stream content
|
162
|
-
yield {
|
163
|
-
kind: 'file',
|
164
|
-
path: 'stream.dat',
|
165
|
-
content: {
|
166
|
-
kind: 'readable',
|
167
|
-
length: 1024,
|
168
|
-
readable: myReadableStream
|
169
|
-
}
|
170
|
-
// ... other properties
|
171
|
-
};
|
172
|
-
|
173
|
-
// Async generator content
|
174
|
-
yield {
|
175
|
-
kind: 'file',
|
176
|
-
path: 'generated.dat',
|
177
|
-
content: {
|
178
|
-
kind: 'generator',
|
179
|
-
length: 2048,
|
180
|
-
generator: myAsyncGenerator // (each yielding `Buffer` instance)
|
181
|
-
}
|
182
|
-
// ... other properties
|
183
|
-
};
|
184
|
-
};
|
185
|
-
```
|
149
|
+
NOTE: The tar format requires file sizes to be stored in the header. This means when using `stream.Readable` or async generators for streaming data, the file size must be known in advance. You can provide this via the `length` option in `createReadableFileItem()` and `createGeneratorFileItem()`. However, if `length` is omitted, all data will be buffered in memory before being written to the tar archive, which could cause performance issues with very large files.
|
186
150
|
|
187
151
|
### Stat reflection options
|
188
152
|
|
153
|
+
When `createReadFileItem()` or `createDirectoryItem()` can access real files or directories, their "stats" metadata can be reflected in the tar archive:
|
154
|
+
|
189
155
|
```typescript
|
190
156
|
import { createReadFileItem, ReflectStats } from 'tar-vern';
|
191
157
|
|
192
|
-
// Don't reflect any file stats (use provided options
|
158
|
+
// Don't reflect any file stats (use provided `options` parameter)
|
193
159
|
yield await createReadFileItem('file.txt', '/source.txt',
|
194
|
-
'none',
|
195
|
-
|
196
|
-
|
197
|
-
|
160
|
+
'none', // Don't reflect
|
161
|
+
{
|
162
|
+
mode: 0o644, // Mode flags
|
163
|
+
uid: 1000, // user id
|
164
|
+
gid: 1000, // group id
|
165
|
+
uname: "foo", // user name
|
166
|
+
gname: "bar" // group name
|
198
167
|
});
|
199
168
|
|
200
|
-
// Reflect all stats except
|
169
|
+
// Reflect all stats except user/group name
|
201
170
|
yield await createReadFileItem('file.txt', '/source.txt',
|
202
|
-
'exceptName'); // except names
|
171
|
+
'exceptName'); // reflect except names
|
203
172
|
|
204
173
|
// Reflect all stats including numeric uid/gid as names
|
205
174
|
yield await createReadFileItem('file.txt', '/source.txt',
|
206
175
|
'all'); // reflect all stats
|
207
176
|
```
|
208
177
|
|
178
|
+
### With GZip compression
|
179
|
+
|
180
|
+
Supported `CompressionTypes`:
|
181
|
+
|
182
|
+
|`CompressionTypes`|Details|
|
183
|
+
|:----|:----|
|
184
|
+
|`none`|Uncompression (default)|
|
185
|
+
|`gzip`|Combined GZip compression stream|
|
186
|
+
|
187
|
+
```typescript
|
188
|
+
import { createTarPacker, storeReaderToFile } from 'tar-vern';
|
189
|
+
|
190
|
+
const itemGenerator = async function*() {
|
191
|
+
yield await createFileItem(
|
192
|
+
'data.txt',
|
193
|
+
'Large amount of data...'
|
194
|
+
);
|
195
|
+
};
|
196
|
+
|
197
|
+
// Create uncompressed tar stream
|
198
|
+
const packer = createTarPacker(itemGenerator(), 'none');
|
199
|
+
await storeReaderToFile(packer, 'archive.tar');
|
200
|
+
```
|
201
|
+
|
209
202
|
----
|
210
203
|
|
211
204
|
## Usage for tar unpacking
|
package/README_pack.md
CHANGED
@@ -17,7 +17,7 @@ A modern TypeScript library for creating tape archives (tar/ustar format) using
|
|
17
17
|
- Multiple content sources: String, Buffer, ReadableStream, file paths and async generators
|
18
18
|
- Metadata preservation: File permissions, ownership, timestamps
|
19
19
|
- Built-in compression: GZip compression support (`tar.gz` format)
|
20
|
-
- No
|
20
|
+
- No external dependencies.
|
21
21
|
|
22
22
|
## Installation
|
23
23
|
|
@@ -29,43 +29,31 @@ npm install tar-vern
|
|
29
29
|
|
30
30
|
## Usage for tar packing
|
31
31
|
|
32
|
-
###
|
32
|
+
### Minimum example
|
33
|
+
|
34
|
+
tar-vern supplies file and directory information to pack through "TypeScript async generator."
|
35
|
+
This allows you to specify pack data with very concise code.
|
33
36
|
|
34
37
|
```typescript
|
35
38
|
import { createTarPacker, storeReaderToFile } from 'tar-vern';
|
36
|
-
import { createWriteStream } from 'fs';
|
37
39
|
|
38
40
|
// Create an async generator for tar entries
|
39
|
-
const
|
41
|
+
const itemGenerator = async function*() {
|
40
42
|
// Add a simple text file
|
41
|
-
yield
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
uname: 'user',
|
46
|
-
gname: 'group',
|
47
|
-
uid: 1000,
|
48
|
-
gid: 1000,
|
49
|
-
date: new Date(),
|
50
|
-
content: 'Hello, world!' // text contents
|
51
|
-
};
|
43
|
+
yield await createFileItem(
|
44
|
+
'hello.txt', // file name
|
45
|
+
'Hello, world!' // text contents
|
46
|
+
);
|
52
47
|
|
53
48
|
// Add a directory
|
54
|
-
yield
|
55
|
-
|
56
|
-
|
57
|
-
mode: 0o755,
|
58
|
-
uname: 'user',
|
59
|
-
gname: 'group',
|
60
|
-
uid: 1000,
|
61
|
-
gid: 1000,
|
62
|
-
date: new Date()
|
63
|
-
};
|
49
|
+
yield await createDirectoryItem('mydir');
|
50
|
+
|
51
|
+
// (Make your own entries with yield expression...)
|
64
52
|
};
|
65
53
|
|
66
|
-
// Create tar stream
|
67
|
-
const packer = createTarPacker(
|
68
|
-
await storeReaderToFile(packer, 'archive.tar'); // Use helper to awaitable
|
54
|
+
// Create GZip compressed tar stream
|
55
|
+
const packer = createTarPacker(itemGenerator(), 'gzip');
|
56
|
+
await storeReaderToFile(packer, 'archive.tar.gz'); // Use helper to awaitable
|
69
57
|
```
|
70
58
|
|
71
59
|
----
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* name: tar-vern
|
3
|
-
* version: 0.
|
3
|
+
* version: 0.3.0
|
4
4
|
* description: Tape archiver library for Typescript
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
6
6
|
* license: MIT
|
@@ -8,7 +8,7 @@
|
|
8
8
|
*/
|
9
9
|
|
10
10
|
export declare const name = "tar-vern";
|
11
|
-
export declare const version = "0.
|
11
|
+
export declare const version = "0.3.0";
|
12
12
|
export declare const description = "Tape archiver library for Typescript";
|
13
13
|
export declare const author = "Kouji Matsui (@kekyo@mi.kekyo.net)";
|
14
14
|
export declare const license = "MIT";
|