市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
555 B

  1. import {getStreamAsArrayBuffer} from './array-buffer.js';
  2. export async function getStreamAsBuffer(stream, options) {
  3. if (!('Buffer' in globalThis)) {
  4. throw new Error('getStreamAsBuffer() is only supported in Node.js');
  5. }
  6. try {
  7. return arrayBufferToNodeBuffer(await getStreamAsArrayBuffer(stream, options));
  8. } catch (error) {
  9. if (error.bufferedData !== undefined) {
  10. error.bufferedData = arrayBufferToNodeBuffer(error.bufferedData);
  11. }
  12. throw error;
  13. }
  14. }
  15. const arrayBufferToNodeBuffer = arrayBuffer => globalThis.Buffer.from(arrayBuffer);