summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/tar/old/doc/example.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/tar/old/doc/example.js')
-rw-r--r--deps/npm/node_modules/tar/old/doc/example.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/deps/npm/node_modules/tar/old/doc/example.js b/deps/npm/node_modules/tar/old/doc/example.js
new file mode 100644
index 0000000000..d29517e49f
--- /dev/null
+++ b/deps/npm/node_modules/tar/old/doc/example.js
@@ -0,0 +1,24 @@
+// request a tar file, and then write it
+require("http").request({...}, function (resp) {
+ resp.pipe(tar.createParser(function (file) {
+ if (file.isDirectory()) {
+ this.pause()
+ return fs.mkdir(file.name, function (er) {
+ if (er) return this.emit("error", er)
+ this.resume()
+ })
+ } else if (file.isSymbolicLink()) {
+ this.pause()
+ return fs.symlink(file.link, file.name, function (er) {
+ if (er) return this.emit("error", er)
+ this.resume()
+ })
+ } else if (file.isFile()) {
+ file.pipe(fs.createWriteStream(file.name))
+ }
+ }))
+ // or maybe just have it do all that internally?
+ resp.pipe(tar.createParser(function (file) {
+ this.create("/extract/target/path", file)
+ }))
+})