Skip to content

fs.writeSync is producing hex not utf8? #2087

@ORESoftware

Description

@ORESoftware

I am non MacOS Node.js version 12.3

I have this:

  const logFD = fs.openSync(somefilepath, 'w+');

  try {
    fs.writeSync(logFD, JSON.stringify({p: pos, b: byteLen}), h * 100, 'utf-8');
  } catch (err) {
    consumer.warn(err.message || err);
  }

I also tried using 'utf8' instead of 'utf-8'

I am always getting hex or whatever this is in the file:

6222 3a34 367d 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 7b22 7022 3a37 3239
3039 2c22 6222 3a32 317d 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 7b22 7022 3a37 3339 3331 2c22
6222 3a31 3032 7d00 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000

is there some reason it's not readable as utf8?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions