Cheddar icon indicating copy to clipboard operation
Cheddar copied to clipboard

fd#write(: Buffer) does not write

Open vihanb opened this issue 8 years ago • 10 comments

Version: v1.0.5

fd#write function when passed a Buffer, does not write any text to the file. However when passed a String object, it correctly writes to the file

vihanb avatar Dec 25 '16 03:12 vihanb

Just convert the Buffer to a string. All 😝

schas002 avatar Dec 25 '16 07:12 schas002

@schas002 however the lovely UTF16 will mangle your bytes.

vihanb avatar Dec 26 '16 18:12 vihanb

Make something that enforces a 256-character encoding on strings. (Like, a Latin1String.) Then convert the Buffer to a string with that rule enforced and you're done. 😝

schas002 avatar Dec 26 '16 18:12 schas002

The problem is that enforces a 256 character encoding. What if you want unicode?

RikerW avatar Dec 26 '16 18:12 RikerW

I suggested a new type.

schas002 avatar Dec 26 '16 19:12 schas002

in "(Like, a Latin1String.)"

schas002 avatar Dec 26 '16 19:12 schas002

That would be slow and it would be a buffer internally anyway.

vihanb avatar Dec 26 '16 19:12 vihanb

Strings are kinda like:

        Input          Internal       Output
  Source Encoding ->   UTF-16 -> Target Encoding

Meaning internally they are stored as UTF-16

vihanb avatar Dec 26 '16 19:12 vihanb

However Output is a buffer anyway

vihanb avatar Dec 26 '16 19:12 vihanb

So we may go only the hard path: using rubber ducks to resolve the problem.

schas002 avatar Dec 26 '16 19:12 schas002