tar-vern 0.3.0 → 1.1.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_pack.md +40 -6
- package/dist/extractor.d.ts +21 -0
- package/dist/extractor.d.ts.map +1 -0
- package/dist/index.cjs +377 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +365 -30
- package/dist/index.js.map +1 -1
- package/dist/packer.d.ts +2 -1
- package/dist/packer.d.ts.map +1 -1
- package/dist/types.d.ts +27 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +34 -8
- package/dist/utils.d.ts.map +1 -1
- package/package.json +19 -3
- package/LICENSE +0 -21
- package/README.md +0 -212
- package/dist/generated/packageMetadata.d.ts +0 -16
- package/dist/generated/packageMetadata.d.ts.map +0 -1
package/README.md
DELETED
@@ -1,212 +0,0 @@
|
|
1
|
-
# tar-vern
|
2
|
-
|
3
|
-
Streaming tape archiver (tar) library for TypeScript/JavaScript.
|
4
|
-
|
5
|
-
[](https://www.repostatus.org/#wip)
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
7
|
-
[](https://www.npmjs.com/package/tar-vern)
|
8
|
-
|
9
|
-
----
|
10
|
-
|
11
|
-
## What is this?
|
12
|
-
|
13
|
-
A modern TypeScript library for creating tape archives (tar/ustar format) using streaming API. Supports both files and directories with metadata preservation, GZip compression, readable streaming, and flexible content sources.
|
14
|
-
|
15
|
-
```mermaid
|
16
|
-
graph LR
|
17
|
-
A[Content Items<br/>* Files<br/>* Directories<br/>* String content<br/>* Buffer content<br/>* Async generators] -->|Stream pipe| B[Writer Stream<br/>'createWriteStream']
|
18
|
-
B --> C[TAR File<br/>'foobar.tar']
|
19
|
-
```
|
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
|
-
|
50
|
-
## Features
|
51
|
-
|
52
|
-
- Streaming API: Memory-efficient processing of large files
|
53
|
-
- Multiple content sources: String, Buffer, ReadableStream, file paths and async generators
|
54
|
-
- Metadata preservation: File permissions, ownership, timestamps
|
55
|
-
- Built-in compression: GZip compression support (`tar.gz` format)
|
56
|
-
- No external dependencies.
|
57
|
-
|
58
|
-
----
|
59
|
-
|
60
|
-
## Installation
|
61
|
-
|
62
|
-
```bash
|
63
|
-
npm install tar-vern
|
64
|
-
```
|
65
|
-
|
66
|
-
## Usage for tar packing
|
67
|
-
|
68
|
-
### EntryItem basis
|
69
|
-
|
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:
|
74
|
-
|
75
|
-
```typescript
|
76
|
-
// Create an async generator for tar entries
|
77
|
-
const itemGenerator = async function*() {
|
78
|
-
// Construct a simple text file item
|
79
|
-
yield {
|
80
|
-
kind: 'file',
|
81
|
-
path: 'hello.txt',
|
82
|
-
mode: 0o644,
|
83
|
-
uname: 'user',
|
84
|
-
gname: 'group',
|
85
|
-
uid: 1000,
|
86
|
-
gid: 1000,
|
87
|
-
date: new Date(),
|
88
|
-
content: 'Hello, world!' // text contents
|
89
|
-
} as EntryItem;
|
90
|
-
|
91
|
-
// Construct a directory item
|
92
|
-
yield {
|
93
|
-
kind: 'directory',
|
94
|
-
path: 'mydir',
|
95
|
-
mode: 0o755,
|
96
|
-
uname: 'user',
|
97
|
-
gname: 'group',
|
98
|
-
uid: 1000,
|
99
|
-
gid: 1000,
|
100
|
-
date: new Date()
|
101
|
-
} as EntryItem;
|
102
|
-
};
|
103
|
-
```
|
104
|
-
|
105
|
-
However, constructing all `EntryItem` objects manually can be tedious. Therefore, helper functions are provided as follows.
|
106
|
-
|
107
|
-
### Helper functions
|
108
|
-
|
109
|
-
Helper functions are provided to simplify the construction of `EntryItem` objects. The following types are available:
|
110
|
-
|
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|
|
118
|
-
|
119
|
-
For example:
|
120
|
-
|
121
|
-
```typescript
|
122
|
-
import { createReadStream } from 'fs';
|
123
|
-
import {
|
124
|
-
createReadFileItem, createDirectoryItem,
|
125
|
-
createReadableFileItem, storeReaderToFile } from 'tar-vern';
|
126
|
-
|
127
|
-
// Configuration easier with item creation functions
|
128
|
-
const itemGenerator = async function*() {
|
129
|
-
// Add file from filesystem (auto-detects metadata)
|
130
|
-
yield await createReadFileItem('archived-name.txt', '/path/to/real/source.txt');
|
131
|
-
|
132
|
-
// Add directory from filesystem
|
133
|
-
yield await createDirectoryItem('dir/sub/name', 'exceptName', {
|
134
|
-
directoryPath: '/path/to/real/dir'
|
135
|
-
});
|
136
|
-
|
137
|
-
// Add from readable stream
|
138
|
-
const stream = createReadStream('/path/to/real/large-file.bin');
|
139
|
-
yield await createReadableFileItem('large-file.bin', stream);
|
140
|
-
};
|
141
|
-
|
142
|
-
// The `packer` generally `stream.Readable`
|
143
|
-
const packer = createTarPacker(itemGenerator());
|
144
|
-
|
145
|
-
// Safer awaitable store file from `stream.Readable`
|
146
|
-
await storeReaderToFile(packer, 'output.tar');
|
147
|
-
```
|
148
|
-
|
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.
|
150
|
-
|
151
|
-
### Stat reflection options
|
152
|
-
|
153
|
-
When `createReadFileItem()` or `createDirectoryItem()` can access real files or directories, their "stats" metadata can be reflected in the tar archive:
|
154
|
-
|
155
|
-
```typescript
|
156
|
-
import { createReadFileItem, ReflectStats } from 'tar-vern';
|
157
|
-
|
158
|
-
// Don't reflect any file stats (use provided `options` parameter)
|
159
|
-
yield await createReadFileItem('file.txt', '/source.txt',
|
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
|
167
|
-
});
|
168
|
-
|
169
|
-
// Reflect all stats except user/group name
|
170
|
-
yield await createReadFileItem('file.txt', '/source.txt',
|
171
|
-
'exceptName'); // reflect except names
|
172
|
-
|
173
|
-
// Reflect all stats including numeric uid/gid as names
|
174
|
-
yield await createReadFileItem('file.txt', '/source.txt',
|
175
|
-
'all'); // reflect all stats
|
176
|
-
```
|
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
|
-
|
202
|
-
----
|
203
|
-
|
204
|
-
## Usage for tar unpacking
|
205
|
-
|
206
|
-
TODO:
|
207
|
-
|
208
|
-
----
|
209
|
-
|
210
|
-
## License
|
211
|
-
|
212
|
-
Under MIT.
|
@@ -1,16 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
* name: tar-vern
|
3
|
-
* version: 0.3.0
|
4
|
-
* description: Tape archiver library for Typescript
|
5
|
-
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
6
|
-
* license: MIT
|
7
|
-
* repository.url: https://github.com/kekyo/tar-vern.git
|
8
|
-
*/
|
9
|
-
|
10
|
-
export declare const name = "tar-vern";
|
11
|
-
export declare const version = "0.3.0";
|
12
|
-
export declare const description = "Tape archiver library for Typescript";
|
13
|
-
export declare const author = "Kouji Matsui (@kekyo@mi.kekyo.net)";
|
14
|
-
export declare const license = "MIT";
|
15
|
-
export declare const repository_url = "https://github.com/kekyo/tar-vern.git";
|
16
|
-
//# sourceMappingURL=packageMetadata.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"packageMetadata.d.ts","sourceRoot":"","sources":["../../src/generated/packageMetadata.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI,aAAa,CAAC;AAC/B,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,WAAW,yCAAyC,CAAC;AAClE,eAAO,MAAM,MAAM,uCAAuC,CAAC;AAC3D,eAAO,MAAM,OAAO,QAAQ,CAAC;AAC7B,eAAO,MAAM,cAAc,0CAA0C,CAAC"}
|