stream-storage
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -168,2 +168,11 @@ 'use strict'; | ||
_destroy(err, cb) { | ||
if (this.readable) { | ||
this.push(null); | ||
this.readable = false; | ||
} | ||
if (this.writable) { | ||
this.end(); | ||
this.writable = false; | ||
} | ||
fs.close(this._fd, (err) => { | ||
@@ -173,3 +182,6 @@ if (!!err) { | ||
} | ||
fs.unlink(this.fileName, cb); | ||
fs.unlink(this.fileName, () => { | ||
this.destroyed = true; | ||
cb(); | ||
}); | ||
}); | ||
@@ -217,6 +229,3 @@ } | ||
.then(resolve) | ||
.catch((err) => { | ||
console.warn(err); | ||
reject(err); | ||
}); | ||
.catch(reject); | ||
}); | ||
@@ -223,0 +232,0 @@ } |
{ | ||
"name": "stream-storage", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Node duplex buffer stream for caching data.", | ||
@@ -15,3 +15,2 @@ "main": "index.js", | ||
}, | ||
"main": "index.js", | ||
"engines": { | ||
@@ -18,0 +17,0 @@ "node": ">= 12.0.0" |
@@ -11,8 +11,7 @@ 'use strict'; | ||
StreamStorage, | ||
DEFAULT_INITIAL_SIZE, | ||
DEFAULT_MAX_SIZE | ||
DEFAULT_INITIAL_SIZE | ||
} = require('..'); | ||
let MAX_CNT = parseInt(process.env.MAX_CNT); | ||
if(isNaN(MAX_CNT)) { | ||
if (isNaN(MAX_CNT)) { | ||
MAX_CNT = 1e3; | ||
@@ -22,3 +21,3 @@ } | ||
let MAX_LEN = parseInt(process.env.MAX_LEN); | ||
if(isNaN(MAX_LEN)) { | ||
if (isNaN(MAX_LEN)) { | ||
MAX_LEN = 1e4; | ||
@@ -44,2 +43,25 @@ } | ||
describe('destroy', function () { | ||
it('free', function () { | ||
const stream = new StreamStorage(); | ||
stream.destroy(); | ||
}); | ||
it('on read', function () { | ||
return new Promise((resolve) => { | ||
const stream = new StreamStorage(); | ||
const onEnd = () => { | ||
if (!stream.readable && !stream.writable) { | ||
resolve(); | ||
} | ||
}; | ||
stream.on('end', onEnd); | ||
stream.on('finish', onEnd); | ||
stream.on('data', (chunk) => {}); | ||
stream.destroy(); | ||
}); | ||
}); | ||
}); | ||
describe('simple string', function () { | ||
@@ -46,0 +68,0 @@ beforeEach(function () { |
16729
436