Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 22, 2024
1 parent dab7e58 commit bd1d1b5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const MAX_WRITE = 16 * 1024
const kContentModeBuffer = 'buffer'
const kContentModeUtf8 = 'utf8'

const [major, minor] = process.versions.node.split('.').map(Number)
const kCopyBuffer = major >= 22 && minor >= 7

function openFile (file, sonic) {
sonic._opening = true
sonic._writing = true
Expand Down Expand Up @@ -639,7 +642,9 @@ function actualWriteBuffer () {
// fs.write will need to copy string to buffer anyway so
// we do it here to avoid the overhead of calculating the buffer size
// in releaseWritingBuf.
this._writingBuf = Buffer.from(this._writingBuf)
if (kCopyBuffer) {
this._writingBuf = Buffer.from(this._writingBuf)
}
fs.write(this.fd, this._writingBuf, release)
}
}
Expand Down

0 comments on commit bd1d1b5

Please sign in to comment.