node.js 958 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.dataUriToBuffer = void 0;
  4. const common_1 = require("./common");
  5. function nodeBuffertoArrayBuffer(nodeBuf) {
  6. if (nodeBuf.byteLength === nodeBuf.buffer.byteLength) {
  7. return nodeBuf.buffer; // large strings may get their own memory allocation
  8. }
  9. const buffer = new ArrayBuffer(nodeBuf.byteLength);
  10. const view = new Uint8Array(buffer);
  11. view.set(nodeBuf);
  12. return buffer;
  13. }
  14. function base64ToArrayBuffer(base64) {
  15. return nodeBuffertoArrayBuffer(Buffer.from(base64, 'base64'));
  16. }
  17. function stringToBuffer(str) {
  18. return nodeBuffertoArrayBuffer(Buffer.from(str, 'ascii'));
  19. }
  20. /**
  21. * Returns a `Buffer` instance from the given data URI `uri`.
  22. *
  23. * @param {String} uri Data URI to turn into a Buffer instance
  24. */
  25. exports.dataUriToBuffer = (0, common_1.makeDataUriToBuffer)({ stringToBuffer, base64ToArrayBuffer });
  26. //# sourceMappingURL=node.js.map