filestream-cache
Advanced tools
Comparing version 1.1.0 to 1.2.0
16
index.js
@@ -20,3 +20,2 @@ var fs = require('fs'); | ||
this.defaultTtl = options.defaultTtl || twelveHoursInSeconds; | ||
this.serveStale = options.serveStale || false; | ||
@@ -228,2 +227,10 @@ // TODO: Where's best to handle errors here? | ||
stream.on('error', function(err) { | ||
cacheStream.then(function(s) { s.end(); | ||
fs.unlink(cachedObjectPath, function(e) { | ||
}); | ||
}); | ||
cachedStream.emit('error', err); | ||
}); | ||
var cachedStream = stream.pipe(through(function(chunk, enc, callback) { | ||
@@ -244,9 +251,2 @@ this.push(chunk, enc); | ||
stream.on('error', function(err) { | ||
cacheStream.then(function(s) { s.end(); | ||
fs.unlink(cachedObjectPath, function(e) { | ||
}); | ||
}); | ||
cachedStream.emit('error', err); | ||
}); | ||
@@ -253,0 +253,0 @@ return cachedStream; |
@@ -17,4 +17,4 @@ { | ||
}, | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"license": "MIT" | ||
} |
@@ -57,2 +57,25 @@ var StreamCache = require('../index'); var fs = require('fs'); | ||
it("should not cache an erroring Readable stream", function(done) { | ||
var testBucket = 'writeThrough#readableerror'; | ||
var cacheKey = 'test'; | ||
var stream = helpers.createErroringReadableStream(); | ||
var testDirectory = helpers.localTestDirectory(testBucket); | ||
var streamCache = new StreamCache(testDirectory); | ||
var cachedStream = streamCache.writeThrough(cacheKey, stream); | ||
cachedStream.on('error', function(err) { | ||
assert.equal(err.code, 'ENOENT'); | ||
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) { | ||
@@ -59,0 +82,0 @@ var streamContent = 'my test stream content'; |
@@ -49,2 +49,7 @@ 'use strict'; | ||
function createErroringReadableStream() { | ||
var stream = fs.createReadStream("/dev/not/a/thing"); | ||
return stream; | ||
} | ||
function testPurgeFunction(cacheKeys, expected, filterFunction) { | ||
@@ -116,3 +121,4 @@ // Add some uniqueness with Date.now() | ||
createStream: createStream, | ||
createErroringReadableStream: createErroringReadableStream, | ||
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
20763
508