isReadableStreamLike.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { __asyncGenerator, __await, __generator } from "tslib";
  2. import { isFunction } from './isFunction';
  3. export function readableStreamLikeToAsyncGenerator(readableStream) {
  4. return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
  5. var reader, _a, value, done;
  6. return __generator(this, function (_b) {
  7. switch (_b.label) {
  8. case 0:
  9. reader = readableStream.getReader();
  10. _b.label = 1;
  11. case 1:
  12. _b.trys.push([1, , 9, 10]);
  13. _b.label = 2;
  14. case 2:
  15. if (!true) return [3, 8];
  16. return [4, __await(reader.read())];
  17. case 3:
  18. _a = _b.sent(), value = _a.value, done = _a.done;
  19. if (!done) return [3, 5];
  20. return [4, __await(void 0)];
  21. case 4: return [2, _b.sent()];
  22. case 5: return [4, __await(value)];
  23. case 6: return [4, _b.sent()];
  24. case 7:
  25. _b.sent();
  26. return [3, 2];
  27. case 8: return [3, 10];
  28. case 9:
  29. reader.releaseLock();
  30. return [7];
  31. case 10: return [2];
  32. }
  33. });
  34. });
  35. }
  36. export function isReadableStreamLike(obj) {
  37. return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
  38. }
  39. //# sourceMappingURL=isReadableStreamLike.js.map