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

Function fromByteArray

docs/tests/v2/es6/js/sanddance.js:78240–78273  ·  view source on GitHub ↗
(uint8)

Source from the content-addressed store, hash-verified

78238}
78239
78240function fromByteArray (uint8) {
78241 var tmp
78242 var len = uint8.length
78243 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
78244 var parts = []
78245 var maxChunkLength = 16383 // must be multiple of 3
78246
78247 // go through the array every three bytes, we'll deal with trailing stuff later
78248 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
78249 parts.push(encodeChunk(
78250 uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
78251 ))
78252 }
78253
78254 // pad the end with zeros, but make sure to not forget the extra bytes
78255 if (extraBytes === 1) {
78256 tmp = uint8[len - 1]
78257 parts.push(
78258 lookup[tmp >> 2] +
78259 lookup[(tmp << 4) & 0x3F] +
78260 '=='
78261 )
78262 } else if (extraBytes === 2) {
78263 tmp = (uint8[len - 2] << 8) + uint8[len - 1]
78264 parts.push(
78265 lookup[tmp >> 10] +
78266 lookup[(tmp >> 4) & 0x3F] +
78267 lookup[(tmp << 2) & 0x3F] +
78268 '='
78269 )
78270 }
78271
78272 return parts.join('')
78273}
78274
78275},{}],"hMTg":[function(require,module,exports) {
78276exports.read = function (buffer, offset, isLE, mLen, nBytes) {

Callers

nothing calls this directly

Calls 1

encodeChunkFunction · 0.70

Tested by

no test coverage detected