(body)
| 1219 | } |
| 1220 | |
| 1221 | function validateBody(body) { |
| 1222 | if (body === undefined) return body; |
| 1223 | // ArrayBuffers, SharedArrayBuffers, and ArrayBufferViews are passed |
| 1224 | // through to the C++ layer which copies the bytes into its own |
| 1225 | // BackingStore. Callers can therefore safely reuse or mutate their |
| 1226 | // input buffers after the call returns. Callers that want to ensure |
| 1227 | // their buffer cannot be mutated after handing it off (for example, |
| 1228 | // when sharing the source with another async consumer) can call |
| 1229 | // ArrayBuffer.prototype.transfer() themselves before passing the |
| 1230 | // buffer. |
| 1231 | if (isArrayBuffer(body) || |
| 1232 | isSharedArrayBuffer(body) || |
| 1233 | isArrayBufferView(body)) { |
| 1234 | return body; |
| 1235 | } |
| 1236 | if (isBlob(body)) return body[kBlobHandle]; |
| 1237 | |
| 1238 | // Strings are encoded as UTF-8. |
| 1239 | if (typeof body === 'string') { |
| 1240 | return Buffer.from(body, 'utf8'); |
| 1241 | } |
| 1242 | |
| 1243 | // FileHandle -- lock it and pass the C++ handle to GetDataQueueFromSource |
| 1244 | // which creates an fd-backed DataQueue entry from the file path. |
| 1245 | if (FileHandle.isFileHandle(body)) { |
| 1246 | if (body[kFileLocked]) { |
| 1247 | throw new ERR_INVALID_STATE('FileHandle is locked'); |
| 1248 | } |
| 1249 | body[kFileLocked] = true; |
| 1250 | return body[kFileHandle]; |
| 1251 | } |
| 1252 | |
| 1253 | throw new ERR_INVALID_ARG_TYPE('options.body', [ |
| 1254 | 'string', |
| 1255 | 'ArrayBuffer', |
| 1256 | 'ArrayBufferView', |
| 1257 | 'Blob', |
| 1258 | 'FileHandle', |
| 1259 | ], body); |
| 1260 | } |
| 1261 | |
| 1262 | /** |
| 1263 | * Parses an alternating [name, value, name, value, ...] array from C++ |
no test coverage detected
searching dependent graphs…