browser-cache-blob-store
Advanced tools
Comparing version 1.0.0 to 1.1.0
48
index.js
@@ -5,10 +5,8 @@ var eos = require('end-of-stream') | ||
var nodeToWebStream = require('readable-stream-node-to-web') | ||
var webStreamToNode = require('./lib/web-to-node-readable-stream') | ||
var nodeToWebStream = require('./lib/node-to-web-readable-stream') | ||
var webToNodeStream = require('./lib/web-to-node-readable-stream') | ||
var noop = function() {} | ||
var listen = function(stream, opts, cb) { | ||
var listen = function (stream, opts, cb) { | ||
if (!cb) return stream | ||
eos(stream, function(err) { | ||
eos(stream, function (err) { | ||
if (err) return cb(err) | ||
@@ -20,7 +18,7 @@ cb(null, opts) | ||
var BlobStore = function(opts) { | ||
if (!window || !window.caches) throw 'Not supported on this platform' | ||
var BlobStore = function (opts) { | ||
if (!window || !window.caches) throw new Error('Not supported on this platform') | ||
if (!(this instanceof BlobStore)) return new BlobStore(opts) | ||
opts = opts || {} | ||
if (typeof opts === 'string') opts = {name:opts} | ||
if (typeof opts === 'string') opts = { name: opts } | ||
@@ -30,4 +28,4 @@ this.name = opts.name || 'blob-store' | ||
BlobStore.prototype.createWriteStream = function(opts, cb) { | ||
if (typeof opts === 'string') opts = {key:opts} | ||
BlobStore.prototype.createWriteStream = function (opts, cb) { | ||
if (typeof opts === 'string') opts = { key: opts } | ||
if (opts.name && !opts.key) opts.key = opts.name | ||
@@ -37,6 +35,12 @@ | ||
var response = new Response(nodeToWebStream(proxy)) | ||
var response = new window.Response(nodeToWebStream(proxy), { | ||
status: 200, | ||
headers: { 'Content-Type': 'application/octet-stream' } | ||
}) | ||
window.caches.open(this.name).then(function (cache) { | ||
cache.put(opts.key, response) | ||
cache.put(opts.key, response).catch(function (err) { | ||
if (cb) cb(err) | ||
proxy.emit('error', err) | ||
}) | ||
}) | ||
@@ -46,3 +50,3 @@ return proxy | ||
BlobStore.prototype.createReadStream = function(key, opts) { | ||
BlobStore.prototype.createReadStream = function (key, opts) { | ||
if (key && typeof key === 'object') return this.createReadStream(key.key, key) | ||
@@ -58,3 +62,3 @@ var proxy = duplexify() | ||
} | ||
proxy.setReadable(webStreamToNode(response.body)) | ||
proxy.setReadable(webToNodeStream(response.body)) | ||
}) | ||
@@ -65,4 +69,4 @@ }) | ||
BlobStore.prototype.exists = function(opts, cb) { | ||
if (typeof opts === 'string') opts = {key:opts} | ||
BlobStore.prototype.exists = function (opts, cb) { | ||
if (typeof opts === 'string') opts = { key: opts } | ||
window.caches.open(this.name).then(function (cache) { | ||
@@ -73,12 +77,6 @@ cache.match(opts.key).then(function (response) { | ||
}) | ||
// if (typeof opts === 'string') opts = {key:opts} | ||
// var key = join(this.path, opts.key) | ||
// fs.stat(key, function(err, stat) { | ||
// if (err && err.code !== 'ENOENT') return cb(err) | ||
// cb(null, !!stat) | ||
// }) | ||
} | ||
BlobStore.prototype.remove = function(opts, cb) { | ||
if (typeof opts === 'string') opts = {key:opts} | ||
BlobStore.prototype.remove = function (opts, cb) { | ||
if (typeof opts === 'string') opts = { key: opts } | ||
window.caches.open(this.name).then(function (cache) { | ||
@@ -85,0 +83,0 @@ cache.delete(opts.key).then(function (deleted) { |
{ | ||
"name": "browser-cache-blob-store", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "blob store that stores blobs using the browser Cache interface", | ||
@@ -8,5 +8,4 @@ "main": "index.js", | ||
"duplexify": "^3.2.0", | ||
"end-of-stream": "^1.0.0", | ||
"end-of-stream": "^1.4.1", | ||
"readable-stream": "^3.0.6", | ||
"readable-stream-node-to-web": "^1.0.1", | ||
"through2": "^2.0.3" | ||
@@ -16,3 +15,7 @@ }, | ||
"abstract-blob-store": "^3.1.0", | ||
"brfs": "^2.0.1", | ||
"browserify": "^16.2.3", | ||
"collect-stream": "^1.2.1", | ||
"from2-buffer": "^1.0.0", | ||
"from2-string": "^1.1.0", | ||
"tape": "^4.9.1", | ||
@@ -23,3 +26,3 @@ "tape-run": "^4.0.0" | ||
"scripts": { | ||
"test": "browserify test.js | tape-run" | ||
"test": "browserify -t brfs test/*.js | tape-run" | ||
}, | ||
@@ -26,0 +29,0 @@ "keywords": [ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
11439
4
9
262
8
1
- Removedreadable-stream-node-to-web@^1.0.1
- Removedreadable-stream-node-to-web@1.0.1(transitive)
Updatedend-of-stream@^1.4.1