Skip to content

fs writeFile after truncate doesn't write at beginning of the file #24923

@kghost

Description

@kghost
  • Version: v11.3.0
  • Platform: Win 10

Test case:

var fs = require('fs').promises;

async function bug() {
  await fs.writeFile('test', '012345678901234567890123456789');
  const fd = await fs.open('test', 'r+');
  await fd.readFile({ encoding: 'utf8' });
  await fd.truncate(0);
  await fd.writeFile('Extra data not at beginning');
  await fd.close();
}

bug();

This will result a file with lots of '\0' at beginning of the file.

And w/o the ability to seek, there is no way to write at the beginning of the file.

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