Skip to content

Commit 6433ea8

Browse files
committed
Replace buffer.buffer with more compatible version
Unforunately some browsers use a version of Buffer that isn't based on a Uint8Array. Add logic to convert when necessary but not make copies when unnecessary.
1 parent 9ebf801 commit 6433ea8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/request.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ ClientRequest.prototype._onFinish = function () {
9696
if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
9797
if (capability.blobConstructor) {
9898
body = new global.Blob(self._body.map(function (buffer) {
99-
return buffer.buffer
99+
if (buffer instanceof Uint8Array) {
100+
return buffer
101+
} else {
102+
var buf = new Uint8Array(buffer.length)
103+
for (var i = 0, len = buf.length; i < len; i++) {
104+
buf[i] = buffer[i]
105+
}
106+
return buf
107+
}
100108
}), {
101109
type: (headersObj['content-type'] || {}).value || ''
102110
})

0 commit comments

Comments
 (0)