File tree Expand file tree Collapse file tree 2 files changed +10
-17
lines changed
Expand file tree Collapse file tree 2 files changed +10
-17
lines changed Original file line number Diff line number Diff line change 11var from = require ( 'from2' )
2- var fs = require ( 'fs' )
32var mm = require ( 'music-metadata' )
43var get = require ( 'lodash.get' )
54
65exports . fromBuffer = fromBuffer
76
87function fromBuffer ( buffer ) {
8+ // TODO: Use https://github.com/rvagg/bl ?
99 return from ( function ( size , next ) {
1010 if ( buffer . length <= 0 ) return next ( null , null )
1111 var chunk = buffer . slice ( 0 , size )
@@ -15,21 +15,14 @@ function fromBuffer (buffer) {
1515}
1616
1717function metadata ( path , cb ) {
18- var audioStream = fs . createReadStream ( path )
19- var returned = false // TODO clean up racy code
20- audioStream . on ( 'error' , ( err ) => {
21- if ( ! returned ) {
22- returned = true
23- return cb ( err )
24- }
25- } )
26- mm . parseStream ( audioStream , { native : true } , function ( err , metadata ) {
27- // important note, the stream is not closed by default. To prevent leaks, you must close it yourself
28- audioStream . destroy ( )
29- if ( ! returned ) {
30- returned = true
31- return cb ( err , err ? null : metadata )
32- }
18+ mm . parseFile ( path , {
19+ native : true ,
20+ duration : true ,
21+ skipCovers : false
22+ } ) . then ( function ( md ) {
23+ return cb ( null , md )
24+ } ) . catch ( function ( err ) {
25+ return cb ( err )
3326 } )
3427}
3528
Original file line number Diff line number Diff line change 6161 "lodash.throttle" : " ^4.1.1" ,
6262 "mkdirp" : " ^0.5.1" ,
6363 "mousetrap" : " ^1.6.1" ,
64- "music-metadata" : " ^0.6.1 " ,
64+ "music-metadata" : " ^0.8.7 " ,
6565 "musicmetadata" : " ^2.0.4" ,
6666 "nanobus" : " ^4.1.0" ,
6767 "nanocomponent" : " ^6.0.0" ,
You can’t perform that action at this time.
0 commit comments