1212var
1313 Stream = require ( '../utils/stream' ) ,
1414 StreamTypes = require ( './stream-types' ) ,
15+ typedArrayIndexOf = require ( '../utils/typed-array' ) . typedArrayIndexOf ,
1516 // Frames that allow different types of text encoding contain a text
1617 // encoding description byte [ID3v2.4.0 section 4.]
1718 textEncodingDescriptionByte = {
5960 }
6061
6162 // parsing fields [ID3v2.4.0 section 4.14.]
62- mimeTypeEndIndex = frame . data . indexOf ( 0 , i ) ;
63+ mimeTypeEndIndex = typedArrayIndexOf ( frame . data , 0 , i ) ;
6364 if ( mimeTypeEndIndex < 0 ) {
6465 // malformed frame
6566 return ;
7374 frame . pictureType = frame . data [ i ] ;
7475 i ++
7576
76- descriptionEndIndex = frame . data . indexOf ( 0 , i ) ;
77+ descriptionEndIndex = typedArrayIndexOf ( frame . data , 0 , i ) ;
7778 if ( descriptionEndIndex < 0 ) {
7879 // malformed frame
7980 return ;
@@ -104,22 +105,29 @@ var
104105 frame . values = frame . value . split ( '\0' ) ;
105106 } ,
106107 'TXXX' : function ( frame ) {
107- var i ;
108+ var descriptionEndIndex ;
109+
108110 if ( frame . data [ 0 ] !== textEncodingDescriptionByte . Utf8 ) {
109111 // ignore frames with unrecognized character encodings
110112 return ;
111113 }
112114
113- for ( i = 1 ; i < frame . data . length ; i ++ ) {
114- if ( frame . data [ i ] === 0 ) {
115- // parse the text fields
116- frame . description = parseUtf8 ( frame . data , 1 , i ) ;
117- // do not include the null terminator in the tag value
118- // frames that allow different types of encoding contain terminated text [ID3v2.4.0 section 4.]
119- frame . value = parseUtf8 ( frame . data , i + 1 , frame . data . length ) . replace ( / \0 * $ / , '' ) ;
120- break ;
121- }
115+ descriptionEndIndex = typedArrayIndexOf ( frame . data , 0 , 1 ) ;
116+
117+ if ( descriptionEndIndex === - 1 ) {
118+ return ;
122119 }
120+
121+ // parse the text fields
122+ frame . description = parseUtf8 ( frame . data , 1 , descriptionEndIndex ) ;
123+ // do not include the null terminator in the tag value
124+ // frames that allow different types of encoding contain terminated text
125+ // [ID3v2.4.0 section 4.]
126+ frame . value = parseUtf8 (
127+ frame . data ,
128+ descriptionEndIndex + 1 ,
129+ frame . data . length
130+ ) . replace ( / \0 * $ / , '' ) ;
123131 frame . data = frame . value ;
124132 } ,
125133 'W*' : function ( frame ) {
@@ -128,22 +136,29 @@ var
128136 frame . url = parseIso88591 ( frame . data , 0 , frame . data . length ) . replace ( / \0 .* $ / , '' ) ;
129137 } ,
130138 'WXXX' : function ( frame ) {
131- var i ;
139+ var descriptionEndIndex ;
140+
132141 if ( frame . data [ 0 ] !== textEncodingDescriptionByte . Utf8 ) {
133142 // ignore frames with unrecognized character encodings
134143 return ;
135144 }
136145
137- for ( i = 1 ; i < frame . data . length ; i ++ ) {
138- if ( frame . data [ i ] === 0 ) {
139- // parse the description and URL fields
140- frame . description = parseUtf8 ( frame . data , 1 , i ) ;
141- // URL fields are always represented as ISO-8859-1 [ID3v2.4.0 section 4.]
142- // if the value is followed by a string termination all the following information should be ignored [ID3v2.4.0 section 4.3]
143- frame . url = parseIso88591 ( frame . data , i + 1 , frame . data . length ) . replace ( / \0 .* $ / , '' ) ;
144- break ;
145- }
146+ descriptionEndIndex = typedArrayIndexOf ( frame . data , 0 , 1 ) ;
147+
148+ if ( descriptionEndIndex === - 1 ) {
149+ return ;
146150 }
151+
152+ // parse the description and URL fields
153+ frame . description = parseUtf8 ( frame . data , 1 , descriptionEndIndex ) ;
154+ // URL fields are always represented as ISO-8859-1 [ID3v2.4.0 section 4.]
155+ // if the value is followed by a string termination all the following information
156+ // should be ignored [ID3v2.4.0 section 4.3]
157+ frame . url = parseIso88591 (
158+ frame . data ,
159+ descriptionEndIndex + 1 ,
160+ frame . data . length
161+ ) . replace ( / \0 .* $ / , '' ) ;
147162 } ,
148163 'PRIV' : function ( frame ) {
149164 var i ;
0 commit comments