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

Function fromString

docs/app/js/sanddance-app.js:113000–113011  ·  view source on GitHub ↗
(string, encoding)

Source from the content-addressed store, hash-verified

112998 return allocUnsafe(size);
112999};
113000function fromString(string, encoding) {
113001 if (typeof encoding !== "string" || encoding === "") encoding = "utf8";
113002 if (!Buffer.isEncoding(encoding)) throw new TypeError("Unknown encoding: " + encoding);
113003 var length = byteLength(string, encoding) | 0;
113004 var buf = createBuffer(length);
113005 var actual = buf.write(string, encoding);
113006 if (actual !== length) // Writing a hex string, for example, that contains invalid characters will
113007 // cause everything after the first invalid character to be ignored. (e.g.
113008 // 'abxxcd' will be treated as 'ab')
113009 buf = buf.slice(0, actual);
113010 return buf;
113011}
113012function fromArrayLike(array) {
113013 var length = array.length < 0 ? 0 : checked(array.length) | 0;
113014 var buf = createBuffer(length);

Callers 1

fromFunction · 0.70

Calls 2

byteLengthFunction · 0.70
createBufferFunction · 0.70

Tested by

no test coverage detected