Skip to content

Commit

Permalink
Remove destroy dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Aug 19, 2020
1 parent ae863ef commit 56d1292
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
11 changes: 5 additions & 6 deletions lib/flatten-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


const Denque = require('denque');
const destroy = require('destroy');
const stream = require('stream');
const util = require('util');

Expand Down Expand Up @@ -56,8 +55,6 @@ function add_data(data, fn) {
this.queue.push([ data, fn ]);
}

function is_stream(s) { return s && typeof s.on === 'function'; }


FlattenStream.prototype._write = function (data, encoding, callback) {
add_data.call(this, data, callback);
Expand All @@ -72,12 +69,14 @@ FlattenStream.prototype.destroy = function () {
this.stream_ended = true;
this.push(null);

if (this.top_chunk_stream) destroy(this.top_chunk_stream);
if (this.top_chunk_stream && typeof this.top_chunk_stream.destroy === 'function') {
this.top_chunk_stream.destroy();
}

while (!this.queue.isEmpty()) {
let data = this.queue.shift()[0];

if (is_stream(data)) destroy(data);
if (data && typeof data.destroy === 'function') data.destroy();
}
};

Expand All @@ -104,7 +103,7 @@ FlattenStream.prototype._read = function () {

let [ data, callback ] = this.queue.shift();

if (is_stream(data)) {
if (data && typeof data.on === 'function') {
// looks like data is a stream
this.state = STATE_FLOWING;
this.top_chunk_stream = data;
Expand Down
5 changes: 1 addition & 4 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const crypto = require('crypto');
const Denque = require('denque');
const debug_err = require('debug')('nntp-server.error');
const debug_net = require('debug')('nntp-server.network');
const destroy = require('destroy');
const serializeError = require('serialize-error').serializeError;
const split2 = require('split2');
const pipeline = require('stream').pipeline;
Expand All @@ -25,8 +24,6 @@ function escape_regexp(str) {
return str.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
}

function is_stream(s) { return s && typeof s.on === 'function'; }


function Command(fn, cmd_line) {
this.state = CMD_WAIT;
Expand Down Expand Up @@ -138,7 +135,7 @@ Session.prototype.current_group = null;
*/
Session.prototype.write = function (data) {
if (!this.out_stream.writable) {
if (is_stream(data)) destroy(data);
if (typeof data.destroy === 'function') data.destroy();
return;
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"dependencies": {
"debug": "^4.0.0",
"denque": "^1.1.1",
"destroy": "^1.0.4",
"serialize-error": "^7.0.1",
"split2": "^3.0.0"
},
Expand Down

0 comments on commit 56d1292

Please sign in to comment.