musicmetadata
Advanced tools
Comparing version 0.3.9 to 0.3.11
@@ -5,22 +5,4 @@ var util = require('util'); | ||
var strtok = require('strtok2'); | ||
var readStream = require('filereader-stream'); | ||
var through = require('through') | ||
var fs = require('fs') | ||
function wrapFileWithStream (file) { | ||
if (file instanceof FileList) { | ||
throw new Error('You have passed a FileList object but we expected a File'); | ||
} | ||
if (!(file instanceof File || file instanceof Blob)) { | ||
throw new Error('You must provide a valid File or Blob object'); | ||
} | ||
var stream = through(null, null, {autoDestroy: false}); | ||
stream.fileSize = function (cb) { | ||
process.nextTick(function () { | ||
cb(file.size); | ||
}) | ||
} | ||
return readStream(file).pipe(stream); | ||
} | ||
var MusicMetadata = module.exports = function (stream, opts) { | ||
@@ -31,31 +13,21 @@ if (!(this instanceof MusicMetadata)) return new MusicMetadata(stream, opts); | ||
if (process.browser) { | ||
this.stream = wrapFileWithStream(stream); | ||
} else { | ||
stream.fileSize = function (cb) { | ||
if (stream.hasOwnProperty('path')) { | ||
fs.stat(stream.path, function (err, stats) { | ||
if (err) throw err; | ||
cb(stats.size); | ||
}); | ||
} else if (opts.fileSize) { | ||
process.nextTick(function() { | ||
cb(opts.fileSize); | ||
}); | ||
} else if (opts.duration) { | ||
self.emit( | ||
'done', | ||
Error('for non file streams, specify the size of the stream with a fileSize option')); | ||
} | ||
stream.fileSize = function (cb) { | ||
if (stream.hasOwnProperty('path')) { | ||
fs.stat(stream.path, function (err, stats) { | ||
if (err) throw err; | ||
cb(stats.size); | ||
}); | ||
} else if (opts.fileSize) { | ||
process.nextTick(function() { | ||
cb(opts.fileSize); | ||
}); | ||
} else if (opts.duration) { | ||
self.emit( | ||
'done', | ||
Error('for non file streams, specify the size of the stream with a fileSize option')); | ||
} | ||
this.stream = stream; | ||
} | ||
events.EventEmitter.call(this); | ||
this.parse(opts); | ||
}; | ||
this.stream = stream; | ||
util.inherits(MusicMetadata, events.EventEmitter); | ||
MusicMetadata.prototype.parse = function (opts) { | ||
this.metadata = { | ||
@@ -66,3 +38,3 @@ title: '', | ||
album: '', | ||
year: "", | ||
year: '', | ||
track: { no: 0, of: 0 }, | ||
@@ -77,3 +49,2 @@ genre: [], | ||
var self = this; | ||
this.stream.once('data', function (result) { | ||
@@ -99,4 +70,8 @@ var parser = common.getParserForMediaType(headerTypes, result); | ||
} | ||
}; | ||
events.EventEmitter.call(this); | ||
} | ||
util.inherits(MusicMetadata, events.EventEmitter); | ||
MusicMetadata.prototype.readEvent = function (event, value) { | ||
@@ -103,0 +78,0 @@ // We only emit aliased events once the 'done' event has been raised, |
{ | ||
"name": "musicmetadata", | ||
"description": "Streaming music metadata parser for node and the browser.", | ||
"version": "0.3.9", | ||
"version": "0.3.11", | ||
"author": "Lee Treveil", | ||
@@ -30,9 +30,11 @@ "dependencies": { | ||
"main": "lib", | ||
"browser": "lib/browser", | ||
"scripts": { | ||
"pretest": "jshint lib/*.js test/*.js", | ||
"test": "[ ! -d 'test/' ] && echo 'The test directory is not included with the project due to the size of the test audio files. If you want to run the tests you can git clone the project.' || tap test/test-*.js" | ||
"test": "[ ! -d 'test/' ] && echo 'The test directory is not included with the project due to the size of the test audio files. If you want to run the tests you can git clone the project.' || prova test/test-*.js", | ||
"test-browser": "prova test/test-js-* test/js-*.js -b", | ||
"dist": "browserify lib/browser.js --standalone 'musicmetadata' -o dist/musicmetadata.js" | ||
}, | ||
"devDependencies": { | ||
"tape": "~2.3.2", | ||
"tap": "~0.4.8", | ||
"prova": "~1.9.0", | ||
"jshint": "~2.4.3" | ||
@@ -39,0 +41,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
2
3
56661
15
1538
1