1 | 'use strict';
|
2 |
|
3 | module.exports = Extract;
|
4 |
|
5 | var Parse = require("../unzip").Parse;
|
6 | var Writer = require("fstream").Writer;
|
7 | var Stream = require('stream').Stream;
|
8 | var path = require('path');
|
9 | var inherits = require('util').inherits;
|
10 |
|
11 | inherits(Extract, Stream);
|
12 |
|
13 | function 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 |
|
41 | Extract.prototype.write = function (data) {
|
42 | this._parser.write(data);
|
43 | };
|
44 |
|
45 | Extract.prototype.end = function (data) {
|
46 | this._parser.end(data);
|
47 | };
|
48 |
|
49 | Extract.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 |