UNPKG

1.15 kBJavaScriptView Raw
1'use strict';
2
3module.exports = Extract;
4
5var Parse = require("../unzip").Parse;
6var Writer = require("fstream").Writer;
7var Stream = require('stream').Stream;
8var path = require('path');
9var inherits = require('util').inherits;
10
11inherits(Extract, Stream);
12
13function Extract (opts) {
14 var self = this;
15 if (!(this instanceof Extract)) {
16 return new Extract(opts);
17 }
18
19 Stream.apply(this);
20
21 this.writable = true;
22 this.readable = true;
23
24 this._parser = Parse();
25 this._parser.on('error', function(err) {
26 self.emit('error', err);
27 });
28
29 var writer = Writer(opts);
30 writer.on('error', function(err) {
31 self.emit('error', err);
32 });
33 writer.on('close', function() {
34 self.emit("end");
35 self.emit("close");
36 });
37
38 this._parser.pipe(writer);
39}
40
41Extract.prototype.write = function (data) {
42 this._parser.write(data);
43};
44
45Extract.prototype.end = function (data) {
46 this._parser.end(data);
47};
48
49Extract.prototype.pipe = function (dest, opts) {
50 var self = this;
51 if (typeof dest.add === "function") {
52 self.on("entry", function (entry) {
53 dest.add(entry);
54 })
55 }
56 return this._parser.pipe.apply(this, arguments);
57};
\No newline at end of file