Skip to content

fs.write does not work on external two-byte strings #18146

Closed
@joyeecheung

Description

@joyeecheung
  • Version: master
  • Platform: all
  • Subsystem: fs

Discovered during #18144

// Flags: --expose_externalize_string

'use strict';

const assert = require('assert');
const fs = require('fs');
const file = 'write-external.txt';
const expected = '中文';
externalizeString(expected);

fs.open(file, 'w', 0o644, function(err, fd) {
  fs.write(fd, expected, 0, 'utf8', function(err, written) {
    fs.closeSync(fd);
    const found = fs.readFileSync(file, 'utf8');
    fs.unlinkSync(file);
    assert.strictEqual(expected, found);  // AssertionError [ERR_ASSERTION]: '中文' strictEqual '-N�e'
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions