MCPcopy Index your code
hub / github.com/microsoft/SandDance / getArrayBufferOrStringFromDataSync

Function getArrayBufferOrStringFromDataSync

docs/app/js/sanddance-app.js:56083–56104  ·  view source on GitHub ↗
(data, loader)

Source from the content-addressed store, hash-verified

56081var _responseUtils = require("../utils/response-utils");
56082var ERR_DATA = "Cannot convert supplied data type";
56083function getArrayBufferOrStringFromDataSync(data, loader) {
56084 if (loader.text && typeof data === "string") return data;
56085 if (data instanceof ArrayBuffer) {
56086 var arrayBuffer = data;
56087 if (loader.text && !loader.binary) {
56088 var textDecoder = new TextDecoder("utf8");
56089 return textDecoder.decode(arrayBuffer);
56090 }
56091 return arrayBuffer;
56092 }
56093 if (ArrayBuffer.isView(data) || (0, _isType.isBuffer)(data)) {
56094 if (loader.text && !loader.binary) {
56095 var _textDecoder = new TextDecoder("utf8");
56096 return _textDecoder.decode(data);
56097 }
56098 var _arrayBuffer = data.buffer;
56099 var byteLength = data.byteLength || data.length;
56100 if (data.byteOffset !== 0 || byteLength !== _arrayBuffer.byteLength) _arrayBuffer = _arrayBuffer.slice(data.byteOffset, data.byteOffset + byteLength);
56101 return _arrayBuffer;
56102 }
56103 throw new Error(ERR_DATA);
56104}
56105function getArrayBufferOrStringFromData(_x, _x2) {
56106 return _getArrayBufferOrStringFromData.apply(this, arguments);
56107}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected