tar 0.1.19 → 1.0.2

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 CHANGED
@@ -1,3 +1,4 @@
1
1
  language: node_js
2
2
  node_js:
3
- - 0.6
3
+ - 0.10
4
+ - 0.11
package/README.md CHANGED
@@ -19,6 +19,8 @@ Returns a through stream. Use
19
19
  pack stream and you will receive tar archive data from the pack
20
20
  stream.
21
21
 
22
+ This only works with directories, it does not work with individual files.
23
+
22
24
  The optional `properties` object are used to set properties in the tar
23
25
  'Global Extended Header'.
24
26
 
@@ -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
- .pipe(tar.Extract({ path: __dirname + "/extract" }))
6
- .on("error", function (er) {
7
- console.error("error here")
8
- })
9
- .on("end", function () {
10
- console.error("done")
11
- })
18
+ .on('error', onError)
19
+ .pipe(extractor);
@@ -0,0 +1,24 @@
1
+ var tar = require("../tar.js")
2
+ , fstream = require("fstream")
3
+ , fs = require("fs")
4
+
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);
19
+
20
+ // This must be a "directory"
21
+ fstream.Reader({ path: __dirname, type: "Directory" })
22
+ .on('error', onError)
23
+ .pipe(packer)
24
+ .pipe(dirDest)
package/lib/extract.js CHANGED
@@ -57,6 +57,10 @@ 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
+
60
64
  // this._fst.on("end", function () {
61
65
  // console.error("\nEEEE Extract End", me._fst.path)
62
66
  // })
package/lib/parse.js CHANGED
@@ -37,6 +37,7 @@ function Parse () {
37
37
  me.readable = true
38
38
  me._stream = new BlockStream(512)
39
39
  me.position = 0
40
+ me._ended = false
40
41
 
41
42
  me._stream.on("error", function (e) {
42
43
  me.emit("error", e)
@@ -118,13 +119,13 @@ Parse.prototype._process = function (c) {
118
119
  // so appending one tarball to another is technically valid.
119
120
  // ending without the eof null blocks is not allowed, however.
120
121
  if (zero) {
121
- this._ended = this._eofStarted
122
+ if (this._eofStarted)
123
+ this._ended = true
122
124
  this._eofStarted = true
123
125
  } else {
124
- this._ended = this._eofStarted = false
126
+ this._eofStarted = false
125
127
  this._startEntry(c)
126
128
  }
127
-
128
129
  }
129
130
 
130
131
  this.position += 512
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.1.19",
5
+ "version": "1.0.2",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git://github.com/isaacs/node-tar.git"
@@ -12,13 +12,15 @@
12
12
  "test": "tap test/*.js"
13
13
  },
14
14
  "dependencies": {
15
- "inherits": "2",
16
15
  "block-stream": "*",
17
- "fstream": "~0.1.8"
16
+ "fstream": "^1.0.2",
17
+ "inherits": "2"
18
18
  },
19
19
  "devDependencies": {
20
+ "graceful-fs": "^3.0.2",
21
+ "rimraf": "1.x",
20
22
  "tap": "0.x",
21
- "rimraf": "1.x"
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
@@ -1,3 +1,6 @@
1
+ // Set the umask, so that it works the same everywhere.
2
+ process.umask(parseInt('22', 8))
3
+
1
4
  var tap = require("tap")
2
5
  , tar = require("../tar.js")
3
6
  , fs = require("fs")
@@ -114,13 +117,6 @@ var tap = require("tap")
114
117
  size: 200,
115
118
  linkpath: undefined,
116
119
  nlink: 2 },
117
- { path: '/200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
118
- mode: '100644',
119
- type: 'Link',
120
- depth: 1,
121
- size: 200,
122
- linkpath: path.join(target, '200-hard'),
123
- nlink: 2 },
124
120
  { path: '/200LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL',
125
121
  mode: '120777',
126
122
  type: 'SymbolicLink',
@@ -128,6 +124,13 @@ var tap = require("tap")
128
124
  size: 200,
129
125
  linkpath: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
130
126
  nlink: 1 },
127
+ { path: '/200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
128
+ mode: '100644',
129
+ type: 'Link',
130
+ depth: 1,
131
+ size: 200,
132
+ linkpath: path.join(target, '200-hard'),
133
+ nlink: 2 },
131
134
  { path: '/c.txt',
132
135
  mode: '100644',
133
136
  type: 'File',
@@ -280,6 +283,12 @@ var tap = require("tap")
280
283
  // So, this is as much a test of fstream.Reader and fstream.Writer
281
284
  // as it is of tar.Extract, but it sort of makes sense.
282
285
 
286
+ tap.test("preclean", function (t) {
287
+ require("rimraf").sync(__dirname + "/tmp/extract-test")
288
+ t.pass("cleaned!")
289
+ t.end()
290
+ })
291
+
283
292
  tap.test("extract test", function (t) {
284
293
  var extract = tar.Extract(target)
285
294
  var inp = fs.createReadStream(file)
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
- // if (ev !== wanted[0] || e.path !== wanted[1].path) {
872
- // console.error(wanted)
873
- // console.error([ev, e.props])
874
- // throw "break"
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]) {