filestream-cache
Advanced tools
Comparing version 1.0.0 to 1.1.0
15
index.js
@@ -227,3 +227,5 @@ var fs = require('fs'); | ||
return stream.pipe(through(function(chunk, enc, callback) { | ||
var cachedStream = stream.pipe(through(function(chunk, enc, callback) { | ||
this.push(chunk, enc); | ||
cacheStream.then(function(cache) { | ||
@@ -233,3 +235,2 @@ cache.write(chunk, enc); | ||
this.push(chunk, enc); | ||
callback(); | ||
@@ -242,2 +243,12 @@ }, function flush(callback) { | ||
})); | ||
stream.on('error', function(err) { | ||
cacheStream.then(function(s) { s.end(); | ||
fs.unlink(cachedObjectPath, function(e) { | ||
}); | ||
}); | ||
cachedStream.emit('error', err); | ||
}); | ||
return cachedStream; | ||
}; | ||
@@ -244,0 +255,0 @@ |
@@ -17,4 +17,4 @@ { | ||
}, | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"license": "MIT" | ||
} |
@@ -34,2 +34,25 @@ var StreamCache = require('../index'); var fs = require('fs'); | ||
describe("#writeThrough(identifier, stream)", function() { | ||
it("should not cache an erroring stream", function(done) { | ||
var testBucket = 'writeThrough#error'; | ||
var cacheKey = 'test'; | ||
var stream = helpers.createErroringStream("test content"); | ||
var testDirectory = helpers.localTestDirectory(testBucket); | ||
var streamCache = new StreamCache(testDirectory); | ||
var cachedStream = streamCache.writeThrough(cacheKey, stream); | ||
cachedStream.on('error', function(err) { | ||
assert.equal(err.message, 'fail'); | ||
var cachedObjectPromise = streamCache._read(cacheKey); | ||
cachedObjectPromise.then(function(object) { | ||
assert.equal(object, false); | ||
rmrf(testDirectory); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it("should write the stream to the cache and return the stream without modification", function(done) { | ||
@@ -36,0 +59,0 @@ var streamContent = 'my test stream content'; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var assert = require('assert'); | ||
var PassThrough = require('stream').PassThrough; | ||
@@ -40,2 +41,11 @@ function localTestDirectory(bucket) { | ||
function createErroringStream(streamContents) { | ||
var stream = new PassThrough(); | ||
stream.write(streamContents); | ||
process.nextTick(function() { | ||
stream.emit('error', new Error("fail")); | ||
}); | ||
return stream; | ||
} | ||
function testPurgeFunction(cacheKeys, expected, filterFunction) { | ||
@@ -106,3 +116,4 @@ // Add some uniqueness with Date.now() | ||
testIsStale: testIsStale, | ||
createStream: createStream | ||
createStream: createStream, | ||
createErroringStream: createErroringStream | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19960
487