Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

music-metadata-browser

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

music-metadata-browser - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

24

dist/fetch/Browser2NodeStream.d.ts
/// <reference types="node" />
/**
* A mock readable-stream, using string to read from
* Converts a Web-API stream into Node stream.Readable class
* Node stream readable: https://nodejs.org/api/stream.html#stream_readable_streams
* Web API readable-stream: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamhttps://nodejs.org/api/stream.html#stream_readable_streams
*/

@@ -12,14 +14,24 @@ import { Readable } from 'stream';

bytesRead: number;
released: boolean;
/**
* Browser stream
* Default web API stream reader
* https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader
*/
private reader;
private pendingRead;
/**
*
* @param stream Readable​Stream: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
*/
constructor(stream: ReadableStream);
_read(): void;
_destroy(error: Error | null, callback: (error: Error | null) => void): void;
/**
* Wait for read to complete and release ReadableStreamReader
* https://nodejs.org/api/stream.html#stream_readable_read_size_1
*/
release(): Promise<void>;
_read(): Promise<void>;
waitForReadToComplete(): Promise<void>;
/**
* Close wrapper
*/
close(): Promise<void>;
private syncAndRelease;
}

@@ -14,3 +14,5 @@ "use strict";

/**
* A mock readable-stream, using string to read from
* Converts a Web-API stream into Node stream.Readable class
* Node stream readable: https://nodejs.org/api/stream.html#stream_readable_streams
* Web API readable-stream: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamhttps://nodejs.org/api/stream.html#stream_readable_streams
*/

@@ -23,41 +25,65 @@ const stream_1 = require("stream");

class Browser2NodeStream extends stream_1.Readable {
/**
*
* @param stream Readable​Stream: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
*/
constructor(stream) {
super();
this.bytesRead = 0;
this.released = false;
this.reader = stream.getReader();
}
/**
* https://nodejs.org/api/stream.html#stream_readable_read_size_1
*/
_read() {
this.pendingRead = this.reader.read();
this.pendingRead.then(res => {
delete this.pendingRead;
if (res.done) {
this.push(null);
return __awaiter(this, void 0, void 0, function* () {
// Should start pushing data into the queue
// Read data from the underlying Web-API-readable-stream
if (this.released) {
return;
}
else {
this.bytesRead += res.value.length;
this.push(res.value);
this.pendingRead = this.reader.read();
try {
const data = yield this.pendingRead;
if (data.done || this.released) {
this.push(null);
}
else {
this.bytesRead += data.value.length;
this.push(data.value);
}
}
finally {
delete this.pendingRead;
}
});
}
_destroy(error, callback) {
this.release().then(() => {
debug(`release browser stream.`);
callback(null);
}).catch(err => {
callback(err);
waitForReadToComplete() {
return __awaiter(this, void 0, void 0, function* () {
if (this.pendingRead) {
yield this.pendingRead;
}
});
}
/**
* Wait for read to complete and release ReadableStreamReader
* Close wrapper
*/
release() {
close() {
return __awaiter(this, void 0, void 0, function* () {
debug(`Release stream...`);
if (this.pendingRead) {
yield this.pendingRead;
this.reader.releaseLock();
}
debug(`close()`);
yield this.syncAndRelease();
});
}
syncAndRelease() {
return __awaiter(this, void 0, void 0, function* () {
debug(`syncAndRelease()`);
this.released = true;
yield this.waitForReadToComplete();
// Trick to release the reader after the read-promise resolved AND returned
yield new Promise(resolve => setTimeout(resolve, 1));
yield this.reader.releaseLock();
});
}
}
exports.Browser2NodeStream = Browser2NodeStream;

@@ -15,3 +15,3 @@ "use strict";

const Browser2NodeStream_1 = require("./fetch/Browser2NodeStream");
const debug = initDebug('music-metadata-browser');
const debug = initDebug('music-metadata-browser:main');
/**

@@ -37,3 +37,3 @@ * Parse audio Stream

debug(`Completed parsing from stream bytesRead=${ns.bytesRead} / fileSize=${options && options.fileSize ? options.fileSize : '?'}`);
yield ns.release();
yield ns.close();
return res;

@@ -81,4 +81,5 @@ });

const res = yield this.parseReadableStream(response.body, contentType, options);
if (!response.body.locked)
yield response.body.cancel();
debug('Closing HTTP-readable-stream...');
yield response.body.cancel();
debug('HTTP-readable-stream closed.');
return res;

@@ -85,0 +86,0 @@ }

{
"name": "music-metadata-browser",
"version": "0.9.0",
"version": "0.9.1",
"description": "Browserifed version of music-metadata",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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