MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / fromString

Function fromString

lib/models/dav.js:2084–2106  ·  view source on GitHub ↗
(that, string, encoding)

Source from the content-addressed store, hash-verified

2082};
2083
2084function fromString (that, string, encoding) {
2085 if (typeof encoding !== 'string' || encoding === '') {
2086 encoding = 'utf8';
2087 }
2088
2089 if (!Buffer.isEncoding(encoding)) {
2090 throw new TypeError('"encoding" must be a valid string encoding')
2091 }
2092
2093 var length = byteLength(string, encoding) | 0;
2094 that = createBuffer(that, length);
2095
2096 var actual = that.write(string, encoding);
2097
2098 if (actual !== length) {
2099 // Writing a hex string, for example, that contains invalid characters will
2100 // cause everything after the first invalid character to be ignored. (e.g.
2101 // 'abxxcd' will be treated as 'ab')
2102 that = that.slice(0, actual);
2103 }
2104
2105 return that
2106}
2107
2108function fromArrayLike (that, array) {
2109 var length = array.length < 0 ? 0 : checked(array.length) | 0;

Callers 1

fromFunction · 0.85

Calls 2

byteLengthFunction · 0.85
createBufferFunction · 0.85

Tested by

no test coverage detected