fetchImage.js 954 B

1234567891011121314151617181920212223
  1. import { __awaiter, __generator } from "tslib";
  2. import { bufferToImage } from './bufferToImage';
  3. import { fetchOrThrow } from './fetchOrThrow';
  4. export function fetchImage(uri) {
  5. return __awaiter(this, void 0, void 0, function () {
  6. var res, blob;
  7. return __generator(this, function (_a) {
  8. switch (_a.label) {
  9. case 0: return [4 /*yield*/, fetchOrThrow(uri)];
  10. case 1:
  11. res = _a.sent();
  12. return [4 /*yield*/, (res).blob()];
  13. case 2:
  14. blob = _a.sent();
  15. if (!blob.type.startsWith('image/')) {
  16. throw new Error("fetchImage - expected blob type to be of type image/*, instead have: " + blob.type + ", for url: " + res.url);
  17. }
  18. return [2 /*return*/, bufferToImage(blob)];
  19. }
  20. });
  21. });
  22. }
  23. //# sourceMappingURL=fetchImage.js.map