Skip to content

Commit 625526e

Browse files
committed
fix: remove is-typedarray and typedarray-to-buffer
our support matrix has support for sending typed arrays directly to tbuffers
1 parent 0b3ffdb commit 625526e

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

lib/index.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const fs = require('fs')
88
const MurmurHash3 = require('imurmurhash')
99
const onExit = require('signal-exit')
1010
const path = require('path')
11-
const isTypedArray = require('is-typedarray')
12-
const typedArrayToBuffer = require('typedarray-to-buffer')
1311
const { promisify } = require('util')
1412
const activeFiles = {}
1513

@@ -110,10 +108,7 @@ async function writeFileAsync (filename, data, options = {}) {
110108
if (options.tmpfileCreated) {
111109
await options.tmpfileCreated(tmpfile)
112110
}
113-
if (isTypedArray(data)) {
114-
data = typedArrayToBuffer(data)
115-
}
116-
if (Buffer.isBuffer(data)) {
111+
if (Buffer.isBuffer(data) || ArrayBuffer.isView(data)) {
117112
await promisify(fs.write)(fd, data, 0, data.length, 0)
118113
} else if (data != null) {
119114
await promisify(fs.write)(fd, String(data), 0, String(options.encoding || 'utf8'))
@@ -215,10 +210,7 @@ function writeFileSync (filename, data, options) {
215210
if (options.tmpfileCreated) {
216211
options.tmpfileCreated(tmpfile)
217212
}
218-
if (isTypedArray(data)) {
219-
data = typedArrayToBuffer(data)
220-
}
221-
if (Buffer.isBuffer(data)) {
213+
if (Buffer.isBuffer(data) || ArrayBuffer.isView(data)) {
222214
fs.writeSync(fd, data, 0, data.length, 0)
223215
} else if (data != null) {
224216
fs.writeSync(fd, String(data), 0, String(options.encoding || 'utf8'))

package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
"homepage": "https://github.com/npm/write-file-atomic",
3232
"dependencies": {
3333
"imurmurhash": "^0.1.4",
34-
"is-typedarray": "^1.0.0",
35-
"signal-exit": "^3.0.7",
36-
"typedarray-to-buffer": "^4.0.0"
34+
"signal-exit": "^3.0.7"
3735
},
3836
"devDependencies": {
3937
"@npmcli/template-oss": "^2.7.1",

0 commit comments

Comments
 (0)