nl_tokens: UCS - 2 ( ISO / IEC 10646 - 1 : 1993 UCS - 2 ) version of readStr . UCS - 2 is the fixed - width two - byte subset of Unicode that can only express values inside the Basic Multilingual Plane ( BMP ) . Note that this method is generally unsuitable for parsing non - trivial UTF - 16 strings which may contain surrogate pairs . [ This is only marginally related though as according to ID3v2 all Unicode strings should be UCS - 2 . ] Further info : * [ How to convert ArrayBuffer to and from String ] ( http : // updates . html5rocks . com / 2012 / 06 / How - to - convert - ArrayBuffer - to - and - from - String ) * [ The encoding spec ] ( http : // encoding . spec . whatwg . org / ) * [ stringencoding shim ] ( https : // code . google . com / p / stringencoding / ) About the BOM : The current implementation will check for and remove the leading BOM from the given view to avoid invisible characters that mess up the resulting strings . MDN s documentation for [ fromCharCode ] ( https : // developer . mozilla . org / en / docs / Web / JavaScript / Reference / Global_Objects / String / fromCharCode ) suggests that it can correctly convert UCS - 2 buffers to strings . And indeed tests performed with UCS - 2 LE encoded frames indicate that it does . However no tests have been made for UCS - 2 BE . ( Kid3 the ID3v2 Tag generator used for tests at the time of this writing goes totally weird when switched to BE )
pl_tokens: function ( view , offset , length ) { // Tweak offset to remove the BOM (LE: FF FE / BE: FE FF) if ( view . getUint16 ( offset ) === 0xFFFE || view . getUint16 ( offset ) === 0xFEFF ) { offset += 2 ; length -= 2 ; } var buffer = view . buffer ; // When offset happens to be an even number of octets, the array-buffer may be wrapped //  in a Uint16Array. In the event that it's _not_, an actual copy has to be made // (Note that Node <= 0.8 as well as IE <= 10 lack an ArrayBuffer#slice. TODO: shim it) if ( offset % 2 === 1 ) { buffer = <mask> . slice ( offset , offset + length ) ; offset = 0 ; } return String . fromCharCode . apply ( null , new Uint16Array ( buffer , offset , length / 2 ) ) ; }