extract-base-iterator 2.3.1 → 2.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  /**
2
- * EntryStream - Simple readable-like stream for entry content
2
+ * EntryStream - Simple readable stream for entry content
3
3
  *
4
- * Extends EventEmitter to emit 'data', 'end', 'error' events.
5
- * Node 0.8 compatible.
4
+ * Extends Readable to emit 'data', 'end', 'error' events.
5
+ * Node 0.8 compatible via readable-stream polyfill.
6
6
  *
7
7
  * This base class is designed to be used by:
8
8
  * - zip-iterator
@@ -10,46 +10,27 @@
10
10
  * - tar-iterator
11
11
  * - Any other archive iterator library
12
12
  */
13
- import { EventEmitter } from 'events';
13
+ import Stream from 'stream';
14
+ declare const ReadableBase: typeof Stream.Readable;
14
15
  /**
15
16
  * Base stream class for archive entry content.
16
17
  * Can be extended for special entry types like sparse files.
17
18
  */
18
- export default class EntryStream extends EventEmitter {
19
- protected _paused: boolean;
19
+ export default class EntryStream extends ReadableBase {
20
20
  protected _ended: boolean;
21
- protected _endEmitted: boolean;
22
- protected _buffered: Buffer[];
21
+ constructor();
23
22
  /**
24
- * Push data to the stream
25
- */
26
- push(data: Buffer): void;
27
- /**
28
- * End the stream
23
+ * Signal end of stream by pushing null
29
24
  */
30
25
  end(): void;
31
- /**
32
- * Resume reading (drain buffered data)
33
- */
34
- resume(): this;
35
- /**
36
- * Pause reading
37
- */
38
- pause(): this;
39
26
  /**
40
27
  * Check if stream has ended
41
28
  */
42
29
  get ended(): boolean;
43
30
  /**
44
- * Pipe to a writable stream
45
- */
46
- pipe<T extends NodeJS.WritableStream>(dest: T): T;
47
- /**
48
- * Flush buffered data
49
- */
50
- protected _flush(): void;
51
- /**
52
- * Emit end event (only once)
31
+ * Required by Readable - called when consumer wants data.
32
+ * Data is pushed externally via push(), nothing to do here.
53
33
  */
54
- protected _emitEnd(): void;
34
+ _read(_size: number): void;
55
35
  }
36
+ export {};
@@ -1,8 +1,8 @@
1
1
  /**
2
- * EntryStream - Simple readable-like stream for entry content
2
+ * EntryStream - Simple readable stream for entry content
3
3
  *
4
- * Extends EventEmitter to emit 'data', 'end', 'error' events.
5
- * Node 0.8 compatible.
4
+ * Extends Readable to emit 'data', 'end', 'error' events.
5
+ * Node 0.8 compatible via readable-stream polyfill.
6
6
  *
7
7
  * This base class is designed to be used by:
8
8
  * - zip-iterator
@@ -10,46 +10,27 @@
10
10
  * - tar-iterator
11
11
  * - Any other archive iterator library
12
12
  */
13
- import { EventEmitter } from 'events';
13
+ import Stream from 'stream';
14
+ declare const ReadableBase: typeof Stream.Readable;
14
15
  /**
15
16
  * Base stream class for archive entry content.
16
17
  * Can be extended for special entry types like sparse files.
17
18
  */
18
- export default class EntryStream extends EventEmitter {
19
- protected _paused: boolean;
19
+ export default class EntryStream extends ReadableBase {
20
20
  protected _ended: boolean;
21
- protected _endEmitted: boolean;
22
- protected _buffered: Buffer[];
21
+ constructor();
23
22
  /**
24
- * Push data to the stream
25
- */
26
- push(data: Buffer): void;
27
- /**
28
- * End the stream
23
+ * Signal end of stream by pushing null
29
24
  */
30
25
  end(): void;
31
- /**
32
- * Resume reading (drain buffered data)
33
- */
34
- resume(): this;
35
- /**
36
- * Pause reading
37
- */
38
- pause(): this;
39
26
  /**
40
27
  * Check if stream has ended
41
28
  */
42
29
  get ended(): boolean;
43
30
  /**
44
- * Pipe to a writable stream
45
- */
46
- pipe<T extends NodeJS.WritableStream>(dest: T): T;
47
- /**
48
- * Flush buffered data
49
- */
50
- protected _flush(): void;
51
- /**
52
- * Emit end event (only once)
31
+ * Required by Readable - called when consumer wants data.
32
+ * Data is pushed externally via push(), nothing to do here.
53
33
  */
54
- protected _emitEnd(): void;
34
+ _read(_size: number): void;
55
35
  }
36
+ export {};
@@ -1,8 +1,8 @@
1
1
  /**
2
- * EntryStream - Simple readable-like stream for entry content
2
+ * EntryStream - Simple readable stream for entry content
3
3
  *
4
- * Extends EventEmitter to emit 'data', 'end', 'error' events.
5
- * Node 0.8 compatible.
4
+ * Extends Readable to emit 'data', 'end', 'error' events.
5
+ * Node 0.8 compatible via readable-stream polyfill.
6
6
  *
7
7
  * This base class is designed to be used by:
8
8
  * - zip-iterator
@@ -19,7 +19,8 @@ Object.defineProperty(exports, "default", {
19
19
  return EntryStream;
20
20
  }
21
21
  });
22
- var _events = require("events");
22
+ var _readablestream = /*#__PURE__*/ _interop_require_default(require("readable-stream"));
23
+ var _stream = /*#__PURE__*/ _interop_require_default(require("stream"));
23
24
  function _assert_this_initialized(self) {
24
25
  if (self === void 0) {
25
26
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -68,6 +69,11 @@ function _inherits(subClass, superClass) {
68
69
  });
69
70
  if (superClass) _set_prototype_of(subClass, superClass);
70
71
  }
72
+ function _interop_require_default(obj) {
73
+ return obj && obj.__esModule ? obj : {
74
+ default: obj
75
+ };
76
+ }
71
77
  function _possible_constructor_return(self, call) {
72
78
  if (call && (_type_of(call) === "object" || typeof call === "function")) {
73
79
  return call;
@@ -93,94 +99,37 @@ function _is_native_reflect_construct() {
93
99
  return !!result;
94
100
  })();
95
101
  }
96
- var EntryStream = /*#__PURE__*/ function(EventEmitter) {
102
+ // Use native streams when available, readable-stream only for Node 0.x
103
+ var major = +process.versions.node.split('.')[0];
104
+ var ReadableBase = major > 0 ? _stream.default.Readable : _readablestream.default.Readable;
105
+ var EntryStream = /*#__PURE__*/ function(ReadableBase) {
97
106
  "use strict";
98
- _inherits(EntryStream, EventEmitter);
107
+ _inherits(EntryStream, ReadableBase);
99
108
  function EntryStream() {
100
109
  _class_call_check(this, EntryStream);
101
110
  var _this;
102
- _this = _call_super(this, EntryStream, arguments), _this._paused = true, _this._ended = false, _this._endEmitted = false, _this._buffered = [];
111
+ // Use a large highWaterMark since data is pushed externally (not from _read)
112
+ // This prevents backpressure issues when pushing synchronously
113
+ _this = _call_super(this, EntryStream, [
114
+ {
115
+ highWaterMark: 1024 * 1024
116
+ }
117
+ ]), _this._ended = false; // 1MB buffer
103
118
  return _this;
104
119
  }
105
120
  var _proto = EntryStream.prototype;
106
121
  /**
107
- * Push data to the stream
108
- */ _proto.push = function push(data) {
109
- if (this._ended) return;
110
- if (this._paused) {
111
- this._buffered.push(data);
112
- } else {
113
- this.emit('data', data);
114
- }
115
- };
116
- /**
117
- * End the stream
122
+ * Signal end of stream by pushing null
118
123
  */ _proto.end = function end() {
119
124
  if (this._ended) return;
120
125
  this._ended = true;
121
- // If not paused, flush and emit end now
122
- if (!this._paused) {
123
- this._flush();
124
- this._emitEnd();
125
- }
126
- // Otherwise, end will be emitted when resume() is called
127
- };
128
- /**
129
- * Resume reading (drain buffered data)
130
- */ _proto.resume = function resume() {
131
- if (!this._paused) return this;
132
- this._paused = false;
133
- this._flush();
134
- // If stream was ended while paused, emit end now
135
- if (this._ended && !this._endEmitted) {
136
- this._emitEnd();
137
- }
138
- return this;
139
- };
140
- /**
141
- * Pause reading
142
- */ _proto.pause = function pause() {
143
- this._paused = true;
144
- return this;
145
- };
146
- /**
147
- * Pipe to a writable stream
148
- */ _proto.pipe = function pipe(dest) {
149
- var self = this;
150
- // Cast to EventEmitter-compatible type for backpressure handling
151
- var emitter = dest;
152
- this.on('data', function onData(chunk) {
153
- var canContinue = dest.write(chunk);
154
- // Handle backpressure if dest returns false
155
- if (canContinue === false && typeof emitter.once === 'function') {
156
- self.pause();
157
- emitter.once('drain', function onDrain() {
158
- self.resume();
159
- });
160
- }
161
- });
162
- this.on('end', function onEnd() {
163
- if (typeof dest.end === 'function') {
164
- dest.end();
165
- }
166
- });
167
- this.resume();
168
- return dest;
169
- };
170
- /**
171
- * Flush buffered data
172
- */ _proto._flush = function _flush() {
173
- while(this._buffered.length > 0){
174
- var chunk = this._buffered.shift();
175
- this.emit('data', chunk);
176
- }
126
+ this.push(null);
177
127
  };
178
128
  /**
179
- * Emit end event (only once)
180
- */ _proto._emitEnd = function _emitEnd() {
181
- if (this._endEmitted) return;
182
- this._endEmitted = true;
183
- this.emit('end');
129
+ * Required by Readable - called when consumer wants data.
130
+ * Data is pushed externally via push(), nothing to do here.
131
+ */ _proto._read = function _read(_size) {
132
+ // Data is pushed externally, nothing to do here
184
133
  };
185
134
  _create_class(EntryStream, [
186
135
  {
@@ -193,5 +142,5 @@ var EntryStream = /*#__PURE__*/ function(EventEmitter) {
193
142
  }
194
143
  ]);
195
144
  return EntryStream;
196
- }(_events.EventEmitter);
145
+ }(ReadableBase);
197
146
  /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/EntryStream.ts"],"sourcesContent":["/**\n * EntryStream - Simple readable-like stream for entry content\n *\n * Extends EventEmitter to emit 'data', 'end', 'error' events.\n * Node 0.8 compatible.\n *\n * This base class is designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n */\n\nimport { EventEmitter } from 'events';\n\n/**\n * Base stream class for archive entry content.\n * Can be extended for special entry types like sparse files.\n */\nexport default class EntryStream extends EventEmitter {\n protected _paused = true;\n protected _ended = false;\n protected _endEmitted = false;\n protected _buffered: Buffer[] = [];\n\n /**\n * Push data to the stream\n */\n push(data: Buffer): void {\n if (this._ended) return;\n\n if (this._paused) {\n this._buffered.push(data);\n } else {\n this.emit('data', data);\n }\n }\n\n /**\n * End the stream\n */\n end(): void {\n if (this._ended) return;\n this._ended = true;\n\n // If not paused, flush and emit end now\n if (!this._paused) {\n this._flush();\n this._emitEnd();\n }\n // Otherwise, end will be emitted when resume() is called\n }\n\n /**\n * Resume reading (drain buffered data)\n */\n resume(): this {\n if (!this._paused) return this;\n this._paused = false;\n this._flush();\n // If stream was ended while paused, emit end now\n if (this._ended && !this._endEmitted) {\n this._emitEnd();\n }\n return this;\n }\n\n /**\n * Pause reading\n */\n pause(): this {\n this._paused = true;\n return this;\n }\n\n /**\n * Check if stream has ended\n */\n get ended(): boolean {\n return this._ended;\n }\n\n /**\n * Pipe to a writable stream\n */\n pipe<T extends NodeJS.WritableStream>(dest: T): T {\n var self = this;\n // Cast to EventEmitter-compatible type for backpressure handling\n var emitter = dest as T & { once?: (event: string, fn: () => void) => void };\n this.on('data', function onData(chunk: Buffer) {\n var canContinue = dest.write(chunk);\n // Handle backpressure if dest returns false\n if (canContinue === false && typeof emitter.once === 'function') {\n self.pause();\n emitter.once('drain', function onDrain() {\n self.resume();\n });\n }\n });\n\n this.on('end', function onEnd() {\n if (typeof dest.end === 'function') {\n dest.end();\n }\n });\n\n this.resume();\n return dest;\n }\n\n /**\n * Flush buffered data\n */\n protected _flush(): void {\n while (this._buffered.length > 0) {\n var chunk = this._buffered.shift();\n this.emit('data', chunk);\n }\n }\n\n /**\n * Emit end event (only once)\n */\n protected _emitEnd(): void {\n if (this._endEmitted) return;\n this._endEmitted = true;\n this.emit('end');\n }\n}\n"],"names":["EntryStream","_paused","_ended","_endEmitted","_buffered","push","data","emit","end","_flush","_emitEnd","resume","pause","pipe","dest","self","emitter","on","onData","chunk","canContinue","write","once","onDrain","onEnd","length","shift","ended","EventEmitter"],"mappings":"AAAA;;;;;;;;;;;CAWC;;;;;;;eAQoBA;;;sBANQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMd,IAAA,AAAMA,4BAAN;;cAAMA;aAAAA;gCAAAA;;gBAAN,kBAAMA,+BACTC,UAAU,YACVC,SAAS,aACTC,cAAc,aACdC,YAAsB,EAAE;;;iBAJfJ;IAMnB;;GAEC,GACDK,OAAAA,IAQC,GARDA,SAAAA,KAAKC,IAAY;QACf,IAAI,IAAI,CAACJ,MAAM,EAAE;QAEjB,IAAI,IAAI,CAACD,OAAO,EAAE;YAChB,IAAI,CAACG,SAAS,CAACC,IAAI,CAACC;Q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G;IACT;IAEA;;GAEC,GACD,OAAUL,MAKT,GALD,SAAUA;QACR,MAAO,IAAI,CAACL,SAAS,CAACqB,MAAM,GAAG,EAAG;YAChC,IAAIN,QAAQ,IAAI,CAACf,SAAS,CAACsB,KAAK;YAChC,IAAI,CAACnB,IAAI,CAAC,QAAQY;QACpB;IACF;IAEA;;GAEC,GACD,OAAUT,QAIT,GAJD,SAAUA;QACR,IAAI,IAAI,CAACP,WAAW,EAAE;QACtB,IAAI,CAACA,WAAW,GAAG;QACnB,IAAI,CAACI,IAAI,CAAC;IACZ;kBA5GmBP;;YA2Df2B,KAAAA;iBAAJ,AAHA;;GAEC,GACD;gBACE,OAAO,IAAI,CAACzB,MAAM;YACpB;;;WA7DmBF;EAAoB4B,oBAAY"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/EntryStream.ts"],"sourcesContent":["/**\n * EntryStream - Simple readable stream for entry content\n *\n * Extends Readable to emit 'data', 'end', 'error' events.\n * Node 0.8 compatible via readable-stream polyfill.\n *\n * This base class is designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n */\n\nimport StreamCompat from 'readable-stream';\nimport Stream from 'stream';\n\n// Use native streams when available, readable-stream only for Node 0.x\nconst major = +process.versions.node.split('.')[0];\nconst ReadableBase: typeof Stream.Readable = major > 0 ? Stream.Readable : (StreamCompat.Readable as typeof Stream.Readable);\n\n/**\n * Base stream class for archive entry content.\n * Can be extended for special entry types like sparse files.\n */\nexport default class EntryStream extends ReadableBase {\n protected _ended = false;\n\n constructor() {\n // Use a large highWaterMark since data is pushed externally (not from _read)\n // This prevents backpressure issues when pushing synchronously\n super({ highWaterMark: 1024 * 1024 }); // 1MB buffer\n }\n\n /**\n * Signal end of stream by pushing null\n */\n end(): void {\n if (this._ended) return;\n this._ended = true;\n this.push(null);\n }\n\n /**\n * Check if stream has ended\n */\n get ended(): boolean {\n return this._ended;\n }\n\n /**\n * Required by Readable - called when consumer wants data.\n * Data is pushed externally via push(), nothing to do here.\n */\n _read(_size: number): void {\n // Data is pushed externally, nothing to do here\n }\n}\n"],"names":["EntryStream","major","process","versions","node","split","ReadableBase","Stream","Readable","StreamCompat","highWaterMark","_ended","end","push","_read","_size","ended"],"mappings":"AAAA;;;;;;;;;;;CAWC;;;;;;;eAaoBA;;;qEAXI;6DACN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEnB,uEAAuE;AACvE,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,eAAuCL,QAAQ,IAAIM,eAAM,CAACC,QAAQ,GAAIC,uBAAY,CAACD,QAAQ;AAMlF,IAAA,AAAMR,4BAAN;;cAAMA;aAAAA;gCAAAA;;QAIjB,6EAA6E;QAC7E,+DAA+D;gBAC/D,kBANiBA;YAMX;gBAAEU,eAAe,OAAO;YAAK;kBAL3BC,SAAS,OAKsB,aAAa;;;iBANnCX;IASnB;;GAEC,GACDY,OAAAA,GAIC,GAJDA,SAAAA;QACE,IAAI,IAAI,CAACD,MAAM,EAAE;QACjB,IAAI,CAACA,MAAM,GAAG;QACd,IAAI,CAACE,IAAI,CAAC;IACZ;IASA;;;GAGC,GACDC,OAAAA,KAEC,GAFDA,SAAAA,MAAMC,KAAa;IACjB,gDAAgD;IAClD;kBA/BmBf;;YAqBfgB,KAAAA;iBAAJ,AAHA;;GAEC,GACD;gBACE,OAAO,IAAI,CAACL,MAAM;YACpB;;;WAvBmBX;EAAoBM"}
@@ -1,8 +1,8 @@
1
1
  /**
2
- * EntryStream - Simple readable-like stream for entry content
2
+ * EntryStream - Simple readable stream for entry content
3
3
  *
4
- * Extends EventEmitter to emit 'data', 'end', 'error' events.
5
- * Node 0.8 compatible.
4
+ * Extends Readable to emit 'data', 'end', 'error' events.
5
+ * Node 0.8 compatible via readable-stream polyfill.
6
6
  *
7
7
  * This base class is designed to be used by:
8
8
  * - zip-iterator
@@ -10,46 +10,27 @@
10
10
  * - tar-iterator
11
11
  * - Any other archive iterator library
12
12
  */
13
- import { EventEmitter } from 'events';
13
+ import Stream from 'stream';
14
+ declare const ReadableBase: typeof Stream.Readable;
14
15
  /**
15
16
  * Base stream class for archive entry content.
16
17
  * Can be extended for special entry types like sparse files.
17
18
  */
18
- export default class EntryStream extends EventEmitter {
19
- protected _paused: boolean;
19
+ export default class EntryStream extends ReadableBase {
20
20
  protected _ended: boolean;
21
- protected _endEmitted: boolean;
22
- protected _buffered: Buffer[];
21
+ constructor();
23
22
  /**
24
- * Push data to the stream
25
- */
26
- push(data: Buffer): void;
27
- /**
28
- * End the stream
23
+ * Signal end of stream by pushing null
29
24
  */
30
25
  end(): void;
31
- /**
32
- * Resume reading (drain buffered data)
33
- */
34
- resume(): this;
35
- /**
36
- * Pause reading
37
- */
38
- pause(): this;
39
26
  /**
40
27
  * Check if stream has ended
41
28
  */
42
29
  get ended(): boolean;
43
30
  /**
44
- * Pipe to a writable stream
45
- */
46
- pipe<T extends NodeJS.WritableStream>(dest: T): T;
47
- /**
48
- * Flush buffered data
49
- */
50
- protected _flush(): void;
51
- /**
52
- * Emit end event (only once)
31
+ * Required by Readable - called when consumer wants data.
32
+ * Data is pushed externally via push(), nothing to do here.
53
33
  */
54
- protected _emitEnd(): void;
34
+ _read(_size: number): void;
55
35
  }
36
+ export {};
@@ -1,55 +1,26 @@
1
1
  /**
2
- * EntryStream - Simple readable-like stream for entry content
2
+ * EntryStream - Simple readable stream for entry content
3
3
  *
4
- * Extends EventEmitter to emit 'data', 'end', 'error' events.
5
- * Node 0.8 compatible.
4
+ * Extends Readable to emit 'data', 'end', 'error' events.
5
+ * Node 0.8 compatible via readable-stream polyfill.
6
6
  *
7
7
  * This base class is designed to be used by:
8
8
  * - zip-iterator
9
9
  * - 7z-iterator
10
10
  * - tar-iterator
11
11
  * - Any other archive iterator library
12
- */ import { EventEmitter } from 'events';
13
- let EntryStream = class EntryStream extends EventEmitter {
14
- /**
15
- * Push data to the stream
16
- */ push(data) {
17
- if (this._ended) return;
18
- if (this._paused) {
19
- this._buffered.push(data);
20
- } else {
21
- this.emit('data', data);
22
- }
23
- }
24
- /**
25
- * End the stream
12
+ */ import StreamCompat from 'readable-stream';
13
+ import Stream from 'stream';
14
+ // Use native streams when available, readable-stream only for Node 0.x
15
+ const major = +process.versions.node.split('.')[0];
16
+ const ReadableBase = major > 0 ? Stream.Readable : StreamCompat.Readable;
17
+ let EntryStream = class EntryStream extends ReadableBase {
18
+ /**
19
+ * Signal end of stream by pushing null
26
20
  */ end() {
27
21
  if (this._ended) return;
28
22
  this._ended = true;
29
- // If not paused, flush and emit end now
30
- if (!this._paused) {
31
- this._flush();
32
- this._emitEnd();
33
- }
34
- // Otherwise, end will be emitted when resume() is called
35
- }
36
- /**
37
- * Resume reading (drain buffered data)
38
- */ resume() {
39
- if (!this._paused) return this;
40
- this._paused = false;
41
- this._flush();
42
- // If stream was ended while paused, emit end now
43
- if (this._ended && !this._endEmitted) {
44
- this._emitEnd();
45
- }
46
- return this;
47
- }
48
- /**
49
- * Pause reading
50
- */ pause() {
51
- this._paused = true;
52
- return this;
23
+ this.push(null);
53
24
  }
54
25
  /**
55
26
  * Check if stream has ended
@@ -57,46 +28,17 @@ let EntryStream = class EntryStream extends EventEmitter {
57
28
  return this._ended;
58
29
  }
59
30
  /**
60
- * Pipe to a writable stream
61
- */ pipe(dest) {
62
- var self = this;
63
- // Cast to EventEmitter-compatible type for backpressure handling
64
- var emitter = dest;
65
- this.on('data', function onData(chunk) {
66
- var canContinue = dest.write(chunk);
67
- // Handle backpressure if dest returns false
68
- if (canContinue === false && typeof emitter.once === 'function') {
69
- self.pause();
70
- emitter.once('drain', function onDrain() {
71
- self.resume();
72
- });
73
- }
74
- });
75
- this.on('end', function onEnd() {
76
- if (typeof dest.end === 'function') {
77
- dest.end();
78
- }
79
- });
80
- this.resume();
81
- return dest;
82
- }
83
- /**
84
- * Flush buffered data
85
- */ _flush() {
86
- while(this._buffered.length > 0){
87
- var chunk = this._buffered.shift();
88
- this.emit('data', chunk);
89
- }
90
- }
91
- /**
92
- * Emit end event (only once)
93
- */ _emitEnd() {
94
- if (this._endEmitted) return;
95
- this._endEmitted = true;
96
- this.emit('end');
31
+ * Required by Readable - called when consumer wants data.
32
+ * Data is pushed externally via push(), nothing to do here.
33
+ */ _read(_size) {
34
+ // Data is pushed externally, nothing to do here
97
35
  }
98
- constructor(...args){
99
- super(...args), this._paused = true, this._ended = false, this._endEmitted = false, this._buffered = [];
36
+ constructor(){
37
+ // Use a large highWaterMark since data is pushed externally (not from _read)
38
+ // This prevents backpressure issues when pushing synchronously
39
+ super({
40
+ highWaterMark: 1024 * 1024
41
+ }), this._ended = false; // 1MB buffer
100
42
  }
101
43
  };
102
44
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/EntryStream.ts"],"sourcesContent":["/**\n * EntryStream - Simple readable-like stream for entry content\n *\n * Extends EventEmitter to emit 'data', 'end', 'error' events.\n * Node 0.8 compatible.\n *\n * This base class is designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n */\n\nimport { EventEmitter } from 'events';\n\n/**\n * Base stream class for archive entry content.\n * Can be extended for special entry types like sparse files.\n */\nexport default class EntryStream extends EventEmitter {\n protected _paused = true;\n protected _ended = false;\n protected _endEmitted = false;\n protected _buffered: Buffer[] = [];\n\n /**\n * Push data to the stream\n */\n push(data: Buffer): void {\n if (this._ended) return;\n\n if (this._paused) {\n this._buffered.push(data);\n } else {\n this.emit('data', data);\n }\n }\n\n /**\n * End the stream\n */\n end(): void {\n if (this._ended) return;\n this._ended = true;\n\n // If not paused, flush and emit end now\n if (!this._paused) {\n this._flush();\n this._emitEnd();\n }\n // Otherwise, end will be emitted when resume() is called\n }\n\n /**\n * Resume reading (drain buffered data)\n */\n resume(): this {\n if (!this._paused) return this;\n this._paused = false;\n this._flush();\n // If stream was ended while paused, emit end now\n if (this._ended && !this._endEmitted) {\n this._emitEnd();\n }\n return this;\n }\n\n /**\n * Pause reading\n */\n pause(): this {\n this._paused = true;\n return this;\n }\n\n /**\n * Check if stream has ended\n */\n get ended(): boolean {\n return this._ended;\n }\n\n /**\n * Pipe to a writable stream\n */\n pipe<T extends NodeJS.WritableStream>(dest: T): T {\n var self = this;\n // Cast to EventEmitter-compatible type for backpressure handling\n var emitter = dest as T & { once?: (event: string, fn: () => void) => void };\n this.on('data', function onData(chunk: Buffer) {\n var canContinue = dest.write(chunk);\n // Handle backpressure if dest returns false\n if (canContinue === false && typeof emitter.once === 'function') {\n self.pause();\n emitter.once('drain', function onDrain() {\n self.resume();\n });\n }\n });\n\n this.on('end', function onEnd() {\n if (typeof dest.end === 'function') {\n dest.end();\n }\n });\n\n this.resume();\n return dest;\n }\n\n /**\n * Flush buffered data\n */\n protected _flush(): void {\n while (this._buffered.length > 0) {\n var chunk = this._buffered.shift();\n this.emit('data', chunk);\n }\n }\n\n /**\n * Emit end event (only once)\n */\n protected _emitEnd(): void {\n if (this._endEmitted) return;\n this._endEmitted = true;\n this.emit('end');\n }\n}\n"],"names":["EventEmitter","EntryStream","push","data","_ended","_paused","_buffered","emit","end","_flush","_emitEnd","resume","_endEmitted","pause","ended","pipe","dest","self","emitter","on","onData","chunk","canContinue","write","once","onDrain","onEnd","length","shift"],"mappings":"AAAA;;;;;;;;;;;CAWC,GAED,SAASA,YAAY,QAAQ,SAAS;AAMvB,IAAA,AAAMC,cAAN,MAAMA,oBAAoBD;IAMvC;;GAEC,GACDE,KAAKC,IAAY,EAAQ;QACvB,IAAI,IAAI,CAACC,MAAM,EAAE;QAEjB,IAAI,IAAI,CAACC,OAAO,EAAE;YAChB,IAAI,CAACC,SAAS,CAACJ,IAAI,CAACC;QACtB,OAAO;YACL,IAAI,CAACI,IAAI,CAAC,QAAQJ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ACH,SAAS,CAACqB,MAAM,GAAG,EAAG;YAChC,IAAIN,QAAQ,IAAI,CAACf,SAAS,CAACsB,KAAK;YAChC,IAAI,CAACrB,IAAI,CAAC,QAAQc;QACpB;IACF;IAEA;;GAEC,GACD,AAAUX,WAAiB;QACzB,IAAI,IAAI,CAACE,WAAW,EAAE;QACtB,IAAI,CAACA,WAAW,GAAG;QACnB,IAAI,CAACL,IAAI,CAAC;IACZ;;QA5Ga,qBACHF,UAAU,WACVD,SAAS,YACTQ,cAAc,YACdN,YAAsB,EAAE;;AAyGpC;AAjHA;;;CAGC,GACD,SAAqBL,yBA6GpB"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/EntryStream.ts"],"sourcesContent":["/**\n * EntryStream - Simple readable stream for entry content\n *\n * Extends Readable to emit 'data', 'end', 'error' events.\n * Node 0.8 compatible via readable-stream polyfill.\n *\n * This base class is designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n */\n\nimport StreamCompat from 'readable-stream';\nimport Stream from 'stream';\n\n// Use native streams when available, readable-stream only for Node 0.x\nconst major = +process.versions.node.split('.')[0];\nconst ReadableBase: typeof Stream.Readable = major > 0 ? Stream.Readable : (StreamCompat.Readable as typeof Stream.Readable);\n\n/**\n * Base stream class for archive entry content.\n * Can be extended for special entry types like sparse files.\n */\nexport default class EntryStream extends ReadableBase {\n protected _ended = false;\n\n constructor() {\n // Use a large highWaterMark since data is pushed externally (not from _read)\n // This prevents backpressure issues when pushing synchronously\n super({ highWaterMark: 1024 * 1024 }); // 1MB buffer\n }\n\n /**\n * Signal end of stream by pushing null\n */\n end(): void {\n if (this._ended) return;\n this._ended = true;\n this.push(null);\n }\n\n /**\n * Check if stream has ended\n */\n get ended(): boolean {\n return this._ended;\n }\n\n /**\n * Required by Readable - called when consumer wants data.\n * Data is pushed externally via push(), nothing to do here.\n */\n _read(_size: number): void {\n // Data is pushed externally, nothing to do here\n }\n}\n"],"names":["StreamCompat","Stream","major","process","versions","node","split","ReadableBase","Readable","EntryStream","end","_ended","push","ended","_read","_size","highWaterMark"],"mappings":"AAAA;;;;;;;;;;;CAWC,GAED,OAAOA,kBAAkB,kBAAkB;AAC3C,OAAOC,YAAY,SAAS;AAE5B,uEAAuE;AACvE,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,eAAuCL,QAAQ,IAAID,OAAOO,QAAQ,GAAIR,aAAaQ,QAAQ;AAMlF,IAAA,AAAMC,cAAN,MAAMA,oBAAoBF;IASvC;;GAEC,GACDG,MAAY;QACV,IAAI,IAAI,CAACC,MAAM,EAAE;QACjB,IAAI,CAACA,MAAM,GAAG;QACd,IAAI,CAACC,IAAI,CAAC;IACZ;IAEA;;GAEC,GACD,IAAIC,QAAiB;QACnB,OAAO,IAAI,CAACF,MAAM;IACpB;IAEA;;;GAGC,GACDG,MAAMC,KAAa,EAAQ;IACzB,gDAAgD;IAClD;IA5BA,aAAc;QACZ,6EAA6E;QAC7E,+DAA+D;QAC/D,KAAK,CAAC;YAAEC,eAAe,OAAO;QAAK,SAL3BL,SAAS,OAKsB,aAAa;IACtD;AAyBF;AApCA;;;CAGC,GACD,SAAqBF,yBAgCpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extract-base-iterator",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "Base iterator for extract iterators like tar-iterator and zip-iterator",
5
5
  "keywords": [
6
6
  "extract",
@@ -49,6 +49,7 @@
49
49
  "next-tick": "*",
50
50
  "object-assign": "*",
51
51
  "queue-cb": "*",
52
+ "readable-stream": "^2.3.8",
52
53
  "rimraf2": "*",
53
54
  "stack-base-iterator": "*"
54
55
  },