MCPcopy Create free account
hub / github.com/bitpay/bitcore-message / fromString

Function fromString

bitcore-message.js:511–533  ·  view source on GitHub ↗
(that, string, encoding)

Source from the content-addressed store, hash-verified

509}
510
511function fromString (that, string, encoding) {
512 if (typeof encoding !== 'string' || encoding === '') {
513 encoding = 'utf8'
514 }
515
516 if (!Buffer.isEncoding(encoding)) {
517 throw new TypeError('"encoding" must be a valid string encoding')
518 }
519
520 var length = byteLength(string, encoding) | 0
521 that = createBuffer(that, length)
522
523 var actual = that.write(string, encoding)
524
525 if (actual !== length) {
526 // Writing a hex string, for example, that contains invalid characters will
527 // cause everything after the first invalid character to be ignored. (e.g.
528 // 'abxxcd' will be treated as 'ab')
529 that = that.slice(0, actual)
530 }
531
532 return that
533}
534
535function fromArrayLike (that, array) {
536 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