1 // Set the umask, so that it works the same everywhere.
2 process.umask(parseInt('22', 8))
4 var tap = require("tap")
5 , tar = require("../tar.js")
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")
12 , fstream = require("fstream")
13 , rimraf = require("rimraf")
14 , mkdirp = require("mkdirp")
41 function slow (fs, method, t1, t2) {
43 if (!orig) return null
44 fs[method] = function () {
45 var args = [].slice.call(arguments)
46 console.error("slow", method, args[0])
49 setTimeout(function () {
50 orig.apply(fs, args.concat(function(er, data) {
51 setTimeout(function() {
59 // Make sure we get the graceful-fs that fstream is using.
62 gfs2 = require("fstream/node_modules/graceful-fs")
65 var slowMethods = ["chown", "chmod", "utimes", "lutimes"]
66 slowMethods.forEach(function (method) {
69 slow(fs, method, t1, t2)
70 slow(gfs, method, t1, t2)
72 slow(gfs2, method, t1, t2)
78 // The extract class basically just pipes the input
79 // to a Reader, and then to a fstream.DirWriter
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.
84 tap.test("preclean", function (t) {
91 tap.test("extract test", function (t) {
92 var extract = tar.Extract(target)
93 var inp = fs.createReadStream(file)
95 // give it a weird buffer size to try to break in odd places
100 extract.on("end", function () {
103 t.equal(ee, expectEntries.length, "should see "+ee+" entries")
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!")
115 extract.on("entry", function (entry) {
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
128 var wanted = expectEntries[ee ++]
130 t.equivalent(found, wanted, "tar entry " + ee + " " + wanted.path)