You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reading files > 4GB doesn't read the correct bytes.
(Maybe related to fix here: #21003)
Code example shows identical code, one with fsPromise, one the old style cb. Example uses sparse file for fast reproduction, but works also with non-sparse files.
let {promises: fs} = require('fs')
let fsOld = require('fs')
let {strict: assert} = require('assert')
const FILE = '/tmp/demo'
const GB = 4
const BUFFER = 2
async function p() {
let input = Buffer.alloc(BUFFER, '-')
let fh = await fs.open(FILE, 'w')
let bytes = await fh.write(input, 0, BUFFER, GB * 1024 * 1024 * 1024)
console.log('bytes', bytes)
await fh.close()
fh = await fs.open(FILE, 'r')
let buffer = Buffer.allocUnsafe(BUFFER)
let result = await fh.read(buffer, 0, BUFFER, GB * 1024 * 1024 * 1024)
await fh.close()
assert.deepEqual(input, result.buffer) // <-- fails
}
async function cb() {
let input = Buffer.alloc(BUFFER, '-')
let fh = await new Promise((res, rej) => fsOld.open(FILE, 'w', (err, data) => err ? rej(err) : res(data)))
let bytes = await new Promise((res, rej) => fsOld.write(fh, input, 0, BUFFER, GB * 1024 * 1024 * 1024, (err, data) => err ? rej(err) : res(data)))
console.log('bytes', bytes)
await new Promise((res, rej) => fsOld.close(fh, e => e ? rej(e) : res()))
fh = await new Promise((res, rej) => fsOld.open(FILE, 'r', (err, data) => err ? rej(err) : res(data)))
let buffer = Buffer.allocUnsafe(BUFFER)
let result = await new Promise((res, rej) => fsOld.read(fh, buffer, 0, BUFFER, GB * 1024 * 1024 * 1024, (err, bytes, buffer) => err ? rej(err) : res({ bytes, buffer })))
console.log('result', result)
await new Promise((res, rej) => fsOld.close(fh, e => e ? rej(e) : res()))
assert.deepEqual(input, result.buffer) // <-- works
}
(async function main() { await cb(); await p() })().catch(e => console.error(e))
The text was updated successfully, but these errors were encountered:
reading files > 4GB doesn't read the correct bytes.
(Maybe related to fix here: #21003)
Code example shows identical code, one with fsPromise, one the old style cb. Example uses sparse file for fast reproduction, but works also with non-sparse files.
The text was updated successfully, but these errors were encountered: