pouchdb-binary-utils
Advanced tools
Comparing version 5.4.4 to 5.4.5
@@ -5,15 +5,2 @@ 'use strict'; | ||
//Can't find original post, but this is close | ||
//http://stackoverflow.com/questions/6965107/ (continues on next line) | ||
//converting-between-strings-and-arraybuffers | ||
function arrayBufferToBinaryString(buffer) { | ||
var binary = ''; | ||
var bytes = new Uint8Array(buffer); | ||
var length = bytes.byteLength; | ||
for (var i = 0; i < length; i++) { | ||
binary += String.fromCharCode(bytes[i]); | ||
} | ||
return binary; | ||
} | ||
var atob$1 = function (str) { | ||
@@ -27,6 +14,2 @@ return atob(str); | ||
function arrayBufferToBase64(buffer) { | ||
return btoa$1(arrayBufferToBinaryString(buffer)); | ||
} | ||
// Abstracts constructing a Blob object, so it also works in older | ||
@@ -77,2 +60,15 @@ // browsers that don't support the native Blob constructor (e.g. | ||
//Can't find original post, but this is close | ||
//http://stackoverflow.com/questions/6965107/ (continues on next line) | ||
//converting-between-strings-and-arraybuffers | ||
function arrayBufferToBinaryString(buffer) { | ||
var binary = ''; | ||
var bytes = new Uint8Array(buffer); | ||
var length = bytes.byteLength; | ||
for (var i = 0; i < length; i++) { | ||
binary += String.fromCharCode(bytes[i]); | ||
} | ||
return binary; | ||
} | ||
// shim for browsers that don't support it | ||
@@ -103,8 +99,14 @@ function readAsBinaryString(blob, callback) { | ||
function blobToBase64(blobOrBuffer, callback) { | ||
function blobToBinaryString(blobOrBuffer, callback) { | ||
readAsBinaryString(blobOrBuffer, function (bin) { | ||
callback(btoa$1(bin)); | ||
callback(bin); | ||
}); | ||
} | ||
function blobToBase64(blobOrBuffer, callback) { | ||
blobToBinaryString(blobOrBuffer, function (base64) { | ||
callback(btoa$1(base64)); | ||
}); | ||
} | ||
// simplified API. universal browser support is assumed | ||
@@ -130,4 +132,2 @@ function readAsArrayBuffer(blob, callback) { | ||
exports.arrayBufferToBase64 = arrayBufferToBase64; | ||
exports.arrayBufferToBinaryString = arrayBufferToBinaryString; | ||
exports.atob = atob$1; | ||
@@ -140,4 +140,5 @@ exports.btoa = btoa$1; | ||
exports.blobOrBufferToBase64 = blobToBase64; | ||
exports.blobOrBufferToBinaryString = blobToBinaryString; | ||
exports.readAsArrayBuffer = readAsArrayBuffer; | ||
exports.readAsBinaryString = readAsBinaryString; | ||
exports.typedBuffer = typedBuffer; |
@@ -5,12 +5,2 @@ 'use strict'; | ||
// In Node, this is just a Buffer rather than an ArrayBuffer | ||
function arrayBufferToBase64(buffer) { | ||
return buffer.toString('binary'); | ||
} | ||
// In Node, this is just a Buffer rather than an ArrayBuffer | ||
function arrayBufferToBinaryString(buffer) { | ||
return buffer.toString('binary'); | ||
} | ||
function thisAtob(str) { | ||
@@ -66,9 +56,36 @@ var base64 = new Buffer(str, 'base64'); | ||
// In Node.js, just convert the Buffer to a Buffer rather than | ||
// convert a Blob to an ArrayBuffer. This function is just a convenience | ||
// function so we can easily switch Node vs browser environments. | ||
function readAsArrayBuffer(buffer, callback) { | ||
callback(buffer); | ||
// not used in Node, but here for completeness | ||
function blobToBase64$1(blobOrBuffer, callback) { | ||
callback(blobOrBuffer.toString('binary')); | ||
} | ||
// simplified API. universal browser support is assumed | ||
function readAsArrayBuffer(blob, callback) { | ||
if (typeof FileReader === 'undefined') { | ||
// fix for Firefox in a web worker: | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=901097 | ||
return callback(new FileReaderSync().readAsArrayBuffer(blob)); | ||
} | ||
var reader = new FileReader(); | ||
reader.onloadend = function (e) { | ||
var result = e.target.result || new ArrayBuffer(0); | ||
callback(result); | ||
}; | ||
reader.readAsArrayBuffer(blob); | ||
} | ||
//Can't find original post, but this is close | ||
//http://stackoverflow.com/questions/6965107/ (continues on next line) | ||
//converting-between-strings-and-arraybuffers | ||
function arrayBufferToBinaryString(buffer) { | ||
var binary = ''; | ||
var bytes = new Uint8Array(buffer); | ||
var length = bytes.byteLength; | ||
for (var i = 0; i < length; i++) { | ||
binary += String.fromCharCode(bytes[i]); | ||
} | ||
return binary; | ||
} | ||
// shim for browsers that don't support it | ||
@@ -99,4 +116,2 @@ function readAsBinaryString(blob, callback) { | ||
exports.arrayBufferToBase64 = arrayBufferToBase64; | ||
exports.arrayBufferToBinaryString = arrayBufferToBinaryString; | ||
exports.atob = thisAtob; | ||
@@ -109,4 +124,5 @@ exports.btoa = thisBtoa; | ||
exports.blobOrBufferToBase64 = blobToBase64; | ||
exports.blobOrBufferToBinaryString = blobToBase64$1; | ||
exports.readAsArrayBuffer = readAsArrayBuffer; | ||
exports.readAsBinaryString = readAsBinaryString; | ||
exports.typedBuffer = typedBuffer; |
{ | ||
"name": "pouchdb-binary-utils", | ||
"version": "5.4.4", | ||
"version": "5.4.5", | ||
"description": "PouchDB utilities for operating on binary strings and Buffers/Blobs.", | ||
@@ -18,4 +18,2 @@ "main": "./lib/index.js", | ||
"./lib/index.js": "./lib/index-browser.js", | ||
"./src/arrayBufferToBase64.js": "./src/arrayBufferToBase64-browser.js", | ||
"./src/arrayBufferToBinaryString.js": "./src/arrayBufferToBinaryString-browser.js", | ||
"./src/base64.js": "./src/base64-browser.js", | ||
@@ -26,5 +24,5 @@ "./src/base64StringToBlobOrBuffer.js": "./src/base64StringToBlobOrBuffer-browser.js", | ||
"./src/blobOrBufferToBase64.js": "./src/blobOrBufferToBase64-browser.js", | ||
"./src/readAsArrayBuffer.js": "./src/readAsArrayBuffer-browser.js", | ||
"./src/blobOrBufferToBinaryString.js": "./src/blobOrBufferToBinaryString-browser.js", | ||
"./src/typedBuffer.js": "./src/typedBuffer-browser.js" | ||
} | ||
} |
@@ -1,7 +0,7 @@ | ||
import readAsBinaryString from './readAsBinaryString'; | ||
import { btoa } from './base64'; | ||
import blobOrBufferToBinaryString from './blobOrBufferToBinaryString'; | ||
function blobToBase64(blobOrBuffer, callback) { | ||
readAsBinaryString(blobOrBuffer, function (bin) { | ||
callback(btoa(bin)); | ||
blobOrBufferToBinaryString(blobOrBuffer, function (base64) { | ||
callback(btoa(base64)); | ||
}); | ||
@@ -8,0 +8,0 @@ } |
@@ -1,3 +0,1 @@ | ||
import arrayBufferToBase64 from './arrayBufferToBase64'; | ||
import arrayBufferToBinaryString from './arrayBufferToBinaryString'; | ||
import {atob, btoa} from './base64'; | ||
@@ -9,2 +7,3 @@ import base64StringToBlobOrBuffer from './base64StringToBlobOrBuffer'; | ||
import blobOrBufferToBase64 from './blobOrBufferToBase64'; | ||
import blobOrBufferToBinaryString from './blobOrBufferToBinaryString'; | ||
import readAsArrayBuffer from './readAsArrayBuffer'; | ||
@@ -15,4 +14,2 @@ import readAsBinaryString from './readAsBinaryString'; | ||
export { | ||
arrayBufferToBase64, | ||
arrayBufferToBinaryString, | ||
atob, | ||
@@ -25,2 +22,3 @@ btoa, | ||
blobOrBufferToBase64, | ||
blobOrBufferToBinaryString, | ||
readAsArrayBuffer, | ||
@@ -27,0 +25,0 @@ readAsBinaryString, |
@@ -1,8 +0,17 @@ | ||
// In Node.js, just convert the Buffer to a Buffer rather than | ||
// convert a Blob to an ArrayBuffer. This function is just a convenience | ||
// function so we can easily switch Node vs browser environments. | ||
function readAsArrayBuffer(buffer, callback) { | ||
callback(buffer); | ||
// simplified API. universal browser support is assumed | ||
function readAsArrayBuffer(blob, callback) { | ||
if (typeof FileReader === 'undefined') { | ||
// fix for Firefox in a web worker: | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=901097 | ||
return callback(new FileReaderSync().readAsArrayBuffer(blob)); | ||
} | ||
var reader = new FileReader(); | ||
reader.onloadend = function (e) { | ||
var result = e.target.result || new ArrayBuffer(0); | ||
callback(result); | ||
}; | ||
reader.readAsArrayBuffer(blob); | ||
} | ||
export default readAsArrayBuffer; |
@@ -1,2 +0,13 @@ | ||
import arrayBufferToBinaryString from './arrayBufferToBinaryString'; | ||
//Can't find original post, but this is close | ||
//http://stackoverflow.com/questions/6965107/ (continues on next line) | ||
//converting-between-strings-and-arraybuffers | ||
function arrayBufferToBinaryString(buffer) { | ||
var binary = ''; | ||
var bytes = new Uint8Array(buffer); | ||
var length = bytes.byteLength; | ||
for (var i = 0; i < length; i++) { | ||
binary += String.fromCharCode(bytes[i]); | ||
} | ||
return binary; | ||
} | ||
@@ -3,0 +14,0 @@ // shim for browsers that don't support it |
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
411
27549
23