filestream-cache
Advanced tools
+8
-8
@@ -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; |
+1
-1
@@ -17,4 +17,4 @@ { | ||
| }, | ||
| "version": "1.1.0", | ||
| "version": "1.2.0", | ||
| "license": "MIT" | ||
| } |
+23
-0
@@ -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 | ||
| }; |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
20763
4.02%508
4.31%