I have read in a file buffer like this:
let imageBuffer
try {
imageBuffer = fs.readFileSync('/some/path/to/image.jpg')
} catch (e) {
console.log('error reading in file', e)
}
Then I try to stat
the buffer:
let imageStats = fs.statSync(imageBuffer)
I get the following error:
Error: Path must be a string without null bytes
But when I check the documentation it says that statSync
accepts a Buffer
:
path: string | Buffer | URL
And I double checked that the Buffer is in fact a Buffer:
console.log(imageBuffer instanceof Buffer) // returns true
Also checked the size:
console.log(imageBuffer.byteLength) // returns 5928109 which is the correct size
So what am I misunderstanding here? Can you only stat
a file path? The error makes it sound this way. But the documentation seems to make it clear that you can provide a Buffer too.
Bug or am I misunderstanding something?