Permalink
Browse files

Extracter example working, hardlink support

  • Loading branch information...
1 parent 3673f24 commit b9c63ea1d253a4110125a8cb0d99040e8062748b @isaacs isaacs committed Nov 7, 2011
Showing with 77 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +11 −0 examples/extracter.js
  3. +64 −0 lib/extract.js
  4. +1 −0 test/fixtures/200-hard
View
@@ -1,2 +1,3 @@
.*.swp
node_modules
+examples/extract/
View
@@ -0,0 +1,11 @@
+var tar = require("../tar.js")
+ , fs = require("fs")
+
+fs.createReadStream(__dirname + "/../test/fixtures/c.tar")
+ .pipe(tar.Extract({ path: __dirname + "/extract" }))
+ .on("error", function (er) {
+ console.error("error here")
+ })
+ .on("end", function () {
+ console.error("done")
+ })
View
@@ -0,0 +1,64 @@
+// give it a tarball and a path, and it'll dump the contents
+
+// process.on("uncaughtException", function (er) {
+// console.error("uncaught", er.stack, er)
+// console.error("errno", global.errno)
+// for (var i in global) console.error(i)
+// throw er
+// })
+
+module.exports = Extract
+
+var tar = require("../tar.js")
+ , fstream = require("fstream")
+ , inherits = require("inherits")
+
+function Extract (opts) {
+ if (!(this instanceof Extract)) return new Extract(opts)
+ tar.Reader.apply(this)
+
+ // have to dump into a directory
+ opts.type = "Directory"
+ opts.Directory = true
+ opts.path = opts.path || path.resolve("node-tar-extract")
+
+ console.error("opts=", opts)
+
+ this._fst = fstream.Writer(opts)
+
+ this._stream.on("data", function (c) {
+ console.error("\t\t\t", c.length)
+ })
+
+ this.pause()
+ this._stream.pause()
+ var me = this
+ this._fst.on("ready", function () {
+ console.error("stat", this.type, this.path)
+ console.error(me.pipe.toString())
+ me.pipe(me._fst)
+ me.resume()
+ })
+
+ this.on("end", function () {
+ console.error("ending")
+ })
+ this.on("entry", function (e) {
+ console.error("entry", e.type, e.path)
+ })
+
+ this._fst.on("entry", function (e) {
+ console.error("writing entry", e.type, e.path)
+ })
+
+ this._fst.on("error", function (e) {
+ console.error("error", e.stack, e.code)
+ })
+
+ this.on("error", function (e) {
+ console.error("my error", e.stack, e.code)
+ })
+
+}
+
+inherits(Extract, tar.Reader)
View
@@ -0,0 +1 @@
+200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

0 comments on commit b9c63ea

Please sign in to comment.