MCPcopy
hub / github.com/feross/buffer / fromObject

Function fromObject

index.js:297–320  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

295}
296
297function fromObject (obj) {
298 if (Buffer.isBuffer(obj)) {
299 const len = checked(obj.length) | 0
300 const buf = createBuffer(len)
301
302 if (buf.length === 0) {
303 return buf
304 }
305
306 obj.copy(buf, 0, 0, len)
307 return buf
308 }
309
310 if (obj.length !== undefined) {
311 if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
312 return createBuffer(0)
313 }
314 return fromArrayLike(obj)
315 }
316
317 if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
318 return fromArrayLike(obj.data)
319 }
320}
321
322function checked (length) {
323 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when

Callers 1

fromFunction · 0.85

Calls 4

checkedFunction · 0.85
createBufferFunction · 0.85
numberIsNaNFunction · 0.85
fromArrayLikeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…