UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

1 lines 2.26 kB
{"version":3,"file":"readFile.native.mjs","sources":["../../../../../src/providers/s3/utils/readFile.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Buffer } from 'buffer';\n// The FileReader in React Native 0.71 did not support `readAsArrayBuffer`. This native implementation accommodates this\n// by attempting to use `readAsArrayBuffer` and changing the file reading strategy if it throws an error.\n// TODO: This file should be removable when we drop support for React Native 0.71\nexport const readFile = (file) => new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => {\n resolve(reader.result);\n };\n reader.onabort = () => {\n reject(new Error('Read aborted'));\n };\n reader.onerror = () => {\n reject(reader.error);\n };\n try {\n reader.readAsArrayBuffer(file);\n }\n catch (e) {\n reader.onload = () => {\n // reference: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL\n // response from readAsDataURL is always prepended with \"data:*/*;base64,\"\n const [, base64Data] = reader.result.split(',');\n const arrayBuffer = Buffer.from(base64Data, 'base64');\n resolve(arrayBuffer);\n };\n reader.readAsDataURL(file);\n }\n});\n"],"names":[],"mappings":";;AAAA;AACA;AAEA;AACA;AACA;AACY,MAAC,QAAQ,GAAG,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AACnE,IAAI,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE;AACnC,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM;AAC1B,QAAQ,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;AAC9B,KAAK;AACL,IAAI,MAAM,CAAC,OAAO,GAAG,MAAM;AAC3B,QAAQ,MAAM,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;AACzC,KAAK;AACL,IAAI,MAAM,CAAC,OAAO,GAAG,MAAM;AAC3B,QAAQ,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;AAC5B,KAAK;AACL,IAAI,IAAI;AACR,QAAQ,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC;AACtC;AACA,IAAI,OAAO,CAAC,EAAE;AACd,QAAQ,MAAM,CAAC,MAAM,GAAG,MAAM;AAC9B;AACA;AACA,YAAY,MAAM,GAAG,UAAU,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;AAC3D,YAAY,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC;AACjE,YAAY,OAAO,CAAC,WAAW,CAAC;AAChC,SAAS;AACT,QAAQ,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC;AAClC;AACA,CAAC;;;;"}