music-metadata-browser
Advanced tools
Comparing version 2.4.3 to 2.5.0
@@ -15,3 +15,3 @@ import { IAudioMetadata, IOptions } from 'music-metadata/lib/type'; | ||
* Parse Web API ReadableStream: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream | ||
* @param stream - ReadableStream | ||
* @param stream - ReadableStream (web stream according WTWG Streams Standard) | ||
* @param fileInfo FileInfo object or MIME-Type | ||
@@ -18,0 +18,0 @@ * @param options - Parsing options |
@@ -24,3 +24,3 @@ "use strict"; | ||
* Parse Web API ReadableStream: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream | ||
* @param stream - ReadableStream | ||
* @param stream - ReadableStream (web stream according WTWG Streams Standard) | ||
* @param fileInfo FileInfo object or MIME-Type | ||
@@ -44,8 +44,7 @@ * @param options - Parsing options | ||
async function parseBlob(blob, options) { | ||
const uint8Array = await convertBlobToUint8Array(blob); | ||
const fileInfo = { mimeType: blob.type, size: blob.size }; | ||
if (blob.name) { | ||
if (blob instanceof File) { | ||
fileInfo.path = blob.name; | ||
} | ||
return mm.parseBuffer(uint8Array, { mimeType: blob.type, size: blob.size }, options); | ||
return parseReadableStream(blob.stream(), { mimeType: blob.type, size: blob.size }, options); | ||
} | ||
@@ -85,25 +84,1 @@ exports.parseBlob = parseBlob; | ||
exports.fetchFromUrl = fetchFromUrl; | ||
/** | ||
* Convert Web API File to Node Buffer | ||
* @param blob - Web API Blob | ||
* @returns Uint8Array | ||
*/ | ||
function convertBlobToUint8Array(blob) { | ||
return new Promise((resolve, reject) => { | ||
const fileReader = new FileReader(); | ||
fileReader.onloadend = event => { | ||
let data = event.target.result; | ||
if (data instanceof ArrayBuffer) { | ||
data = new Uint8Array(data); | ||
} | ||
resolve(data); | ||
}; | ||
fileReader.onerror = error => { | ||
reject(new Error(error.type)); | ||
}; | ||
fileReader.onabort = error => { | ||
reject(new Error(error.type)); | ||
}; | ||
fileReader.readAsArrayBuffer(blob); | ||
}); | ||
} |
{ | ||
"name": "music-metadata-browser", | ||
"version": "2.4.3", | ||
"version": "2.5.0", | ||
"description": "Browserifed version of music-metadata", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -131,3 +131,3 @@ [![Karma CI](https://github.com/Borewit/music-metadata-browser/actions/workflows/karma-ci.yml/badge.svg)](https://github.com/Borewit/music-metadata-browser/actions/workflows/karma-ci.yml) | ||
(async () => { | ||
let blob; | ||
let blob; // File or Blob | ||
@@ -144,9 +144,8 @@ const metadata = await musicMetadata.parseBlob(blob); | ||
mm.parseReadableStream(readableStream) | ||
.then(metadata => { | ||
console.log(util.inspect(metadata, { showHidden: false, depth: null })); | ||
readableStream.close(); | ||
}); | ||
(async () => { | ||
const metadata = await mm.parseReadableStream(readableStream); | ||
console.log(util.inspect(metadata, { showHidden: false, depth: null })); | ||
}); | ||
``` | ||
Parse from a Web API [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream). | ||
Parse from a Web API [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) (web stream according [WTWG Streams Standard](https://streams.spec.whatwg.org/)). | ||
@@ -153,0 +152,0 @@ If available, pass the mime-type and file-size. Without the mime-type, the content will be audio type will be automatically detected. |
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
33716
218
292