MCPcopy Create free account
hub / github.com/microsoft/SandDance / fromObject

Function fromObject

docs/app/js/sanddance-app.js:113036–113049  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

113034 return buf;
113035}
113036function fromObject(obj) {
113037 if (Buffer.isBuffer(obj)) {
113038 var len = checked(obj.length) | 0;
113039 var buf = createBuffer(len);
113040 if (buf.length === 0) return buf;
113041 obj.copy(buf, 0, 0, len);
113042 return buf;
113043 }
113044 if (obj.length !== undefined) {
113045 if (typeof obj.length !== "number" || numberIsNaN(obj.length)) return createBuffer(0);
113046 return fromArrayLike(obj);
113047 }
113048 if (obj.type === "Buffer" && Array.isArray(obj.data)) return fromArrayLike(obj.data);
113049}
113050function checked(length) {
113051 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
113052 // length is NaN (which is otherwise coerced to zero.)

Callers 1

fromFunction · 0.70

Calls 5

checkedFunction · 0.70
createBufferFunction · 0.70
numberIsNaNFunction · 0.70
fromArrayLikeFunction · 0.70
copyMethod · 0.45

Tested by

no test coverage detected