tar 0.1.20 → 1.0.3
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/.travis.yml +2 -1
- package/examples/extracter.js +15 -7
- package/examples/packer.js +17 -3
- package/lib/extract.js +8 -0
- package/lib/parse.js +1 -1
- package/package.json +5 -3
- package/test/extract-move.js +132 -0
- package/test/extract.js +1 -1
- package/test/fixtures.tgz +0 -0
- package/test/pack-no-proprietary.js +33 -1
- package/test/pack.js +42 -5
package/.travis.yml
CHANGED
package/examples/extracter.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
var tar = require("../tar.js")
|
|
2
2
|
, fs = require("fs")
|
|
3
3
|
|
|
4
|
+
|
|
5
|
+
function onError(err) {
|
|
6
|
+
console.error('An error occurred:', err)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function onEnd() {
|
|
10
|
+
console.log('Extracted!')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
var extractor = tar.Extract({path: __dirname + "/extract"})
|
|
14
|
+
.on('error', onError)
|
|
15
|
+
.on('end', onEnd);
|
|
16
|
+
|
|
4
17
|
fs.createReadStream(__dirname + "/../test/fixtures/c.tar")
|
|
5
|
-
.
|
|
6
|
-
.
|
|
7
|
-
console.error("error here")
|
|
8
|
-
})
|
|
9
|
-
.on("end", function () {
|
|
10
|
-
console.error("done")
|
|
11
|
-
})
|
|
18
|
+
.on('error', onError)
|
|
19
|
+
.pipe(extractor);
|
package/examples/packer.js
CHANGED
|
@@ -2,9 +2,23 @@ var tar = require("../tar.js")
|
|
|
2
2
|
, fstream = require("fstream")
|
|
3
3
|
, fs = require("fs")
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var dirDest = fs.createWriteStream('dir.tar')
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function onError(err) {
|
|
9
|
+
console.error('An error occurred:', err)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function onEnd() {
|
|
13
|
+
console.log('Packed!')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var packer = tar.Pack({ noProprietary: true })
|
|
17
|
+
.on('error', onError)
|
|
18
|
+
.on('end', onEnd);
|
|
6
19
|
|
|
7
20
|
// This must be a "directory"
|
|
8
21
|
fstream.Reader({ path: __dirname, type: "Directory" })
|
|
9
|
-
.
|
|
10
|
-
.pipe(
|
|
22
|
+
.on('error', onError)
|
|
23
|
+
.pipe(packer)
|
|
24
|
+
.pipe(dirDest)
|
package/lib/extract.js
CHANGED
|
@@ -57,6 +57,14 @@ function Extract (opts) {
|
|
|
57
57
|
me.resume()
|
|
58
58
|
})
|
|
59
59
|
|
|
60
|
+
this._fst.on('error', function(err) {
|
|
61
|
+
me.emit('error', err)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
this._fst.on('drain', function() {
|
|
65
|
+
me.emit('drain')
|
|
66
|
+
})
|
|
67
|
+
|
|
60
68
|
// this._fst.on("end", function () {
|
|
61
69
|
// console.error("\nEEEE Extract End", me._fst.path)
|
|
62
70
|
// })
|
package/lib/parse.js
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
|
3
3
|
"name": "tar",
|
|
4
4
|
"description": "tar for node",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "1.0.3",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git://github.com/isaacs/node-tar.git"
|
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"block-stream": "*",
|
|
16
|
-
"fstream": "
|
|
16
|
+
"fstream": "^1.0.2",
|
|
17
17
|
"inherits": "2"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"graceful-fs": "^3.0.2",
|
|
21
|
+
"rimraf": "1.x",
|
|
20
22
|
"tap": "0.x",
|
|
21
|
-
"
|
|
23
|
+
"mkdirp": "^0.5.0"
|
|
22
24
|
},
|
|
23
25
|
"license": "BSD"
|
|
24
26
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Set the umask, so that it works the same everywhere.
|
|
2
|
+
process.umask(parseInt('22', 8))
|
|
3
|
+
|
|
4
|
+
var tap = require("tap")
|
|
5
|
+
, tar = require("../tar.js")
|
|
6
|
+
, fs = require("fs")
|
|
7
|
+
, gfs = require("graceful-fs")
|
|
8
|
+
, path = require("path")
|
|
9
|
+
, file = path.resolve(__dirname, "fixtures/dir.tar")
|
|
10
|
+
, target = path.resolve(__dirname, "tmp/extract-test")
|
|
11
|
+
, index = 0
|
|
12
|
+
, fstream = require("fstream")
|
|
13
|
+
, rimraf = require("rimraf")
|
|
14
|
+
, mkdirp = require("mkdirp")
|
|
15
|
+
|
|
16
|
+
, ee = 0
|
|
17
|
+
, expectEntries = [
|
|
18
|
+
{
|
|
19
|
+
"path" : "dir/",
|
|
20
|
+
"mode" : "750",
|
|
21
|
+
"type" : "5",
|
|
22
|
+
"depth" : undefined,
|
|
23
|
+
"size" : 0,
|
|
24
|
+
"linkpath" : "",
|
|
25
|
+
"nlink" : undefined,
|
|
26
|
+
"dev" : undefined,
|
|
27
|
+
"ino" : undefined
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path" : "dir/sub/",
|
|
31
|
+
"mode" : "750",
|
|
32
|
+
"type" : "5",
|
|
33
|
+
"depth" : undefined,
|
|
34
|
+
"size" : 0,
|
|
35
|
+
"linkpath" : "",
|
|
36
|
+
"nlink" : undefined,
|
|
37
|
+
"dev" : undefined,
|
|
38
|
+
"ino" : undefined
|
|
39
|
+
} ]
|
|
40
|
+
|
|
41
|
+
function slow (fs, method, t1, t2) {
|
|
42
|
+
var orig = fs[method]
|
|
43
|
+
if (!orig) return null
|
|
44
|
+
fs[method] = function () {
|
|
45
|
+
var args = [].slice.call(arguments)
|
|
46
|
+
console.error("slow", method, args[0])
|
|
47
|
+
var cb = args.pop()
|
|
48
|
+
|
|
49
|
+
setTimeout(function () {
|
|
50
|
+
orig.apply(fs, args.concat(function(er, data) {
|
|
51
|
+
setTimeout(function() {
|
|
52
|
+
cb(er, data)
|
|
53
|
+
}, t2)
|
|
54
|
+
}))
|
|
55
|
+
}, t1)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Make sure we get the graceful-fs that fstream is using.
|
|
60
|
+
var gfs2
|
|
61
|
+
try {
|
|
62
|
+
gfs2 = require("fstream/node_modules/graceful-fs")
|
|
63
|
+
} catch (er) {}
|
|
64
|
+
|
|
65
|
+
var slowMethods = ["chown", "chmod", "utimes", "lutimes"]
|
|
66
|
+
slowMethods.forEach(function (method) {
|
|
67
|
+
var t1 = 500
|
|
68
|
+
var t2 = 0
|
|
69
|
+
slow(fs, method, t1, t2)
|
|
70
|
+
slow(gfs, method, t1, t2)
|
|
71
|
+
if (gfs2) {
|
|
72
|
+
slow(gfs2, method, t1, t2)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// The extract class basically just pipes the input
|
|
79
|
+
// to a Reader, and then to a fstream.DirWriter
|
|
80
|
+
|
|
81
|
+
// So, this is as much a test of fstream.Reader and fstream.Writer
|
|
82
|
+
// as it is of tar.Extract, but it sort of makes sense.
|
|
83
|
+
|
|
84
|
+
tap.test("preclean", function (t) {
|
|
85
|
+
rimraf.sync(target)
|
|
86
|
+
/mkdirp.sync(target)
|
|
87
|
+
t.pass("cleaned!")
|
|
88
|
+
t.end()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
tap.test("extract test", function (t) {
|
|
92
|
+
var extract = tar.Extract(target)
|
|
93
|
+
var inp = fs.createReadStream(file)
|
|
94
|
+
|
|
95
|
+
// give it a weird buffer size to try to break in odd places
|
|
96
|
+
inp.bufferSize = 1234
|
|
97
|
+
|
|
98
|
+
inp.pipe(extract)
|
|
99
|
+
|
|
100
|
+
extract.on("end", function () {
|
|
101
|
+
rimraf.sync(target)
|
|
102
|
+
|
|
103
|
+
t.equal(ee, expectEntries.length, "should see "+ee+" entries")
|
|
104
|
+
|
|
105
|
+
// should get no more entries after end
|
|
106
|
+
extract.removeAllListeners("entry")
|
|
107
|
+
extract.on("entry", function (e) {
|
|
108
|
+
t.fail("Should not get entries after end!")
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
t.end()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
extract.on("entry", function (entry) {
|
|
116
|
+
var found =
|
|
117
|
+
{ path: entry.path
|
|
118
|
+
, mode: entry.props.mode.toString(8)
|
|
119
|
+
, type: entry.props.type
|
|
120
|
+
, depth: entry.props.depth
|
|
121
|
+
, size: entry.props.size
|
|
122
|
+
, linkpath: entry.props.linkpath
|
|
123
|
+
, nlink: entry.props.nlink
|
|
124
|
+
, dev: entry.props.dev
|
|
125
|
+
, ino: entry.props.ino
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var wanted = expectEntries[ee ++]
|
|
129
|
+
|
|
130
|
+
t.equivalent(found, wanted, "tar entry " + ee + " " + wanted.path)
|
|
131
|
+
})
|
|
132
|
+
})
|
package/test/extract.js
CHANGED
|
@@ -118,7 +118,7 @@ var tap = require("tap")
|
|
|
118
118
|
linkpath: undefined,
|
|
119
119
|
nlink: 2 },
|
|
120
120
|
{ path: '/200LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL',
|
|
121
|
-
mode: '
|
|
121
|
+
mode: '120777',
|
|
122
122
|
type: 'SymbolicLink',
|
|
123
123
|
depth: 1,
|
|
124
124
|
size: 200,
|
package/test/fixtures.tgz
CHANGED
|
Binary file
|
|
@@ -149,6 +149,38 @@ var tap = require("tap")
|
|
|
149
149
|
devmin: 0,
|
|
150
150
|
fill: '' } ]
|
|
151
151
|
|
|
152
|
+
, [ 'entry',
|
|
153
|
+
{ path: 'fixtures/dir/',
|
|
154
|
+
mode: 488,
|
|
155
|
+
uid: uid,
|
|
156
|
+
gid: gid,
|
|
157
|
+
size: 0,
|
|
158
|
+
type: '5',
|
|
159
|
+
linkpath: '',
|
|
160
|
+
ustar: 'ustar\u0000',
|
|
161
|
+
ustarver: '00',
|
|
162
|
+
uname: '',
|
|
163
|
+
gname: '',
|
|
164
|
+
devmaj: 0,
|
|
165
|
+
devmin: 0,
|
|
166
|
+
fill: '' } ]
|
|
167
|
+
|
|
168
|
+
, [ 'entry',
|
|
169
|
+
{ path: 'fixtures/dir/sub/',
|
|
170
|
+
mode: 488,
|
|
171
|
+
uid: uid,
|
|
172
|
+
gid: gid,
|
|
173
|
+
size: 0,
|
|
174
|
+
type: '5',
|
|
175
|
+
linkpath: '',
|
|
176
|
+
ustar: 'ustar\u0000',
|
|
177
|
+
ustarver: '00',
|
|
178
|
+
uname: '',
|
|
179
|
+
gname: '',
|
|
180
|
+
devmaj: 0,
|
|
181
|
+
devmin: 0,
|
|
182
|
+
fill: '' } ]
|
|
183
|
+
|
|
152
184
|
, [ 'entry',
|
|
153
185
|
{ path: 'fixtures/foo.js',
|
|
154
186
|
mode: 420,
|
|
@@ -823,7 +855,7 @@ function runTest (t, doGH) {
|
|
|
823
855
|
t.equal(ev, wanted[0], "event type should be "+wanted[0])
|
|
824
856
|
|
|
825
857
|
if (ev !== wanted[0] || e.path !== wanted[1].path) {
|
|
826
|
-
console.error(wanted)
|
|
858
|
+
console.error("wanted", wanted)
|
|
827
859
|
console.error([ev, e.props])
|
|
828
860
|
e.on("end", function () {
|
|
829
861
|
console.error(e.fields)
|
package/test/pack.js
CHANGED
|
@@ -177,6 +177,39 @@ var tap = require("tap")
|
|
|
177
177
|
devmin: 0,
|
|
178
178
|
fill: '' } ]
|
|
179
179
|
|
|
180
|
+
, [ 'entry',
|
|
181
|
+
{ path: 'fixtures/dir/',
|
|
182
|
+
mode: 488,
|
|
183
|
+
uid: uid,
|
|
184
|
+
gid: gid,
|
|
185
|
+
size: 0,
|
|
186
|
+
type: '5',
|
|
187
|
+
linkpath: '',
|
|
188
|
+
ustar: 'ustar\u0000',
|
|
189
|
+
ustarver: '00',
|
|
190
|
+
uname: '',
|
|
191
|
+
gname: '',
|
|
192
|
+
devmaj: 0,
|
|
193
|
+
devmin: 0,
|
|
194
|
+
fill: '' } ]
|
|
195
|
+
|
|
196
|
+
, [ 'entry',
|
|
197
|
+
{ path: 'fixtures/dir/sub/',
|
|
198
|
+
mode: 488,
|
|
199
|
+
uid: uid,
|
|
200
|
+
gid: gid,
|
|
201
|
+
size: 0,
|
|
202
|
+
type: '5',
|
|
203
|
+
linkpath: '',
|
|
204
|
+
ustar: 'ustar\u0000',
|
|
205
|
+
ustarver: '00',
|
|
206
|
+
uname: '',
|
|
207
|
+
gname: '',
|
|
208
|
+
devmaj: 0,
|
|
209
|
+
devmin: 0,
|
|
210
|
+
fill: '' } ]
|
|
211
|
+
|
|
212
|
+
|
|
180
213
|
, [ 'entry',
|
|
181
214
|
{ path: 'fixtures/foo.js',
|
|
182
215
|
mode: 420,
|
|
@@ -868,11 +901,15 @@ function runTest (t, doGH) {
|
|
|
868
901
|
}
|
|
869
902
|
t.equal(ev, wanted[0], "event type should be "+wanted[0])
|
|
870
903
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
904
|
+
if (ev !== wanted[0] || e.path !== wanted[1].path) {
|
|
905
|
+
console.error("wanted", wanted)
|
|
906
|
+
console.error([ev, e.props])
|
|
907
|
+
e.on("end", function () {
|
|
908
|
+
console.error(e.fields)
|
|
909
|
+
throw "break"
|
|
910
|
+
})
|
|
911
|
+
}
|
|
912
|
+
|
|
876
913
|
|
|
877
914
|
t.has(e.props, wanted[1], "properties "+wanted[1].path)
|
|
878
915
|
if (wanted[2]) {
|