Socket
Socket
Sign inDemoInstall

@wordpress/blob

Package Overview
Dependencies
Maintainers
6
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/blob - npm Package Compare versions

Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2

48

build-module/index.js

@@ -1,7 +0,4 @@

import _Promise from "babel-runtime/core-js/promise";
/**
* Browser dependencies
*/
var _window = window,
fetch = _window.fetch;
var _window$URL = window.URL,

@@ -14,26 +11,41 @@ createObjectURL = _window$URL.createObjectURL,

export function createBlobURL(blob) {
var url = createObjectURL(blob);
/**
* Create a blob URL from a file.
*
* @param {File} file The file to create a blob URL for.
*
* @return {string} The blob URL.
*/
export function createBlobURL(file) {
var url = createObjectURL(file);
cache[url] = blob;
cache[url] = file;
return url;
return url;
}
/**
* Retrieve a file based on a blob URL. The file must have been created by
* `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
* `undefined`.
*
* @param {string} url The blob URL.
*
* @return {?File} The file for the blob URL.
*/
export function getBlobByURL(url) {
if (cache[url]) {
return _Promise.resolve(cache[url]);
}
return fetch(url).then(function (response) {
return response.blob();
});
return cache[url];
}
/**
* Remove the resource and file cache from memory.
*
* @param {string} url The blob URL.
*/
export function revokeBlobURL(url) {
if (cache[url]) {
revokeObjectURL(url);
}
if (cache[url]) {
revokeObjectURL(url);
}
delete cache[url];
delete cache[url];
}
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var _promise = require("babel-runtime/core-js/promise");
var _promise2 = _interopRequireDefault(_promise);
exports.createBlobURL = createBlobURL;
exports.getBlobByURL = getBlobByURL;
exports.revokeBlobURL = revokeBlobURL;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Browser dependencies
*/
var _window = window,
fetch = _window.fetch;
var _window$URL = window.URL,

@@ -29,26 +19,41 @@ createObjectURL = _window$URL.createObjectURL,

function createBlobURL(blob) {
var url = createObjectURL(blob);
/**
* Create a blob URL from a file.
*
* @param {File} file The file to create a blob URL for.
*
* @return {string} The blob URL.
*/
function createBlobURL(file) {
var url = createObjectURL(file);
cache[url] = blob;
cache[url] = file;
return url;
return url;
}
/**
* Retrieve a file based on a blob URL. The file must have been created by
* `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
* `undefined`.
*
* @param {string} url The blob URL.
*
* @return {?File} The file for the blob URL.
*/
function getBlobByURL(url) {
if (cache[url]) {
return _promise2.default.resolve(cache[url]);
}
return fetch(url).then(function (response) {
return response.blob();
});
return cache[url];
}
/**
* Remove the resource and file cache from memory.
*
* @param {string} url The blob URL.
*/
function revokeBlobURL(url) {
if (cache[url]) {
revokeObjectURL(url);
}
if (cache[url]) {
revokeObjectURL(url);
}
delete cache[url];
delete cache[url];
}
{
"name": "@wordpress/blob",
"version": "1.0.0-alpha.1",
"version": "1.0.0-alpha.2",
"description": "Blob utils for WordPress",

@@ -5,0 +5,0 @@ "author": "The WordPress Contributors",

/**
* Browser dependencies
*/
const { fetch } = window;
const { createObjectURL, revokeObjectURL } = window.URL;

@@ -9,6 +8,13 @@

export function createBlobURL( blob ) {
const url = createObjectURL( blob );
/**
* Create a blob URL from a file.
*
* @param {File} file The file to create a blob URL for.
*
* @return {string} The blob URL.
*/
export function createBlobURL( file ) {
const url = createObjectURL( file );
cache[ url ] = blob;
cache[ url ] = file;

@@ -18,10 +24,20 @@ return url;

/**
* Retrieve a file based on a blob URL. The file must have been created by
* `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
* `undefined`.
*
* @param {string} url The blob URL.
*
* @return {?File} The file for the blob URL.
*/
export function getBlobByURL( url ) {
if ( cache[ url ] ) {
return Promise.resolve( cache[ url ] );
}
return fetch( url ).then( ( response ) => response.blob() );
return cache[ url ];
}
/**
* Remove the resource and file cache from memory.
*
* @param {string} url The blob URL.
*/
export function revokeBlobURL( url ) {

@@ -28,0 +44,0 @@ if ( cache[ url ] ) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc