rochars / wavefile

Create, read and write wav files according to the specs. :star: :notes: :heart:
MIT License
226 stars 48 forks source link

Unicode text is not read correctly #13

Closed DanielSWolf closed 5 years ago

DanielSWolf commented 5 years ago

I have a WAVE file with cue points. One of them has the label "Marker 01 abcäöüß". Yet when I call listCuePoints(), the corresponding label string is "Marker 01 abcä�ö�ü�ß�".

The reason for this is that the method WaveFile.readZSTR_ tries to convert the string byte by byte, which gives wrong results for multi-byte UTF-8 code points.

I found an easy fix. Given that this project is currently unmaintained, I'm not opening a PR. Instead, here's a small snippet of code that patches the bug at runtime:

const WaveFile = require('wavefile');
const { unpackString } = require('byte-data');

WaveFile.prototype.readZSTR_ = function patchedReadZSTR_(bytes, start = 0) {
  let end = start;
  while (end < bytes.length && bytes[end]) end++;

  return unpackString(bytes, start, end);
}
rochars commented 5 years ago

This is issue is fixed in version 8.4.5.

Thanks!