image-js / iobuffer

Read and write binary data in ArrayBuffers
http://image-js.github.io/iobuffer/
MIT License
43 stars 6 forks source link

Question: reading other text encodings #53

Closed ghost closed 1 year ago

ghost commented 1 year ago

I don't know whether it would be useful to have a method of this sort:

decodeText(nBytes, encoding){
  const text = new TextDecoder(encoding).decode(this.readBytes(nBytes))
  offset += nBytes
  return text 
}

For methods like latin1, windows-1252 or these from MDN (SO-8859-2, KOI8-R, GBK, etc.)

targos commented 1 year ago

SGTM!

targos commented 1 year ago

We can make encoding default to utf-8

ghost commented 1 year ago

I can try a PR.

I am not sure whether there is a specific type for the encodings, maybe can be taken from TextDecoder argument.

targos commented 1 year ago

I don't think a specific type is available. It seems to be just string for TextDecoder.

targos commented 1 year ago

Done in https://github.com/image-js/iobuffer/pull/55