diff --git a/README.md b/README.md index 11c4e4a..29ac658 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,6 @@ npm install react-native-fast-io --save - React Native 0.76 or higher - Nitro Modules -- Polyfills: - - TextDecoder, e.g. `@bacons/text-decoder` - - Streams, e.g. `web-streams-polyfill/polyfill` - - AsyncIterator, e.g. `@azure/core-asynciterator-polyfill` ### Usage diff --git a/example/index.js b/example/index.js index 9de06bd..bf54297 100644 --- a/example/index.js +++ b/example/index.js @@ -1,5 +1,3 @@ -import '@bacons/text-decoder/install' -import 'web-streams-polyfill/polyfill' import '@azure/core-asynciterator-polyfill' import { AppRegistry } from 'react-native' diff --git a/example/package.json b/example/package.json index 715821d..0a28703 100644 --- a/example/package.json +++ b/example/package.json @@ -8,14 +8,11 @@ "server": "bun server/index.ts" }, "dependencies": { - "@azure/core-asynciterator-polyfill": "^1.0.2", - "@bacons/text-decoder": "^0.0.0", "cli-table3": "^0.6.5", "react": "18.3.1", "react-native": "0.76.0", "react-native-fast-io": "0.1.1", - "react-native-nitro-modules": "^0.15.0", - "web-streams-polyfill": "^4.0.0" + "react-native-nitro-modules": "^0.15.0" }, "devDependencies": { "@babel/core": "^7.20.0", diff --git a/example/tests/filesystem.tsx b/example/tests/filesystem.tsx index d85f54f..928d8c0 100644 --- a/example/tests/filesystem.tsx +++ b/example/tests/filesystem.tsx @@ -1,7 +1,7 @@ import React, { useState } from 'react' import { StyleSheet, Text, TouchableOpacity, View } from 'react-native' import { fetch } from 'react-native-fast-io/fetch' -import { showOpenFilePicker } from 'react-native-fast-io/fs' +import { File, showOpenFilePicker } from 'react-native-fast-io/fs' import { CompressionStream } from 'react-native-fast-io/streams' import { BASE_URL } from './benchmark' diff --git a/packages/react-native-fast-io/package.json b/packages/react-native-fast-io/package.json index 0b9082e..34f500d 100644 --- a/packages/react-native-fast-io/package.json +++ b/packages/react-native-fast-io/package.json @@ -46,7 +46,9 @@ "react-native-nitro-modules": "^0.15.0" }, "dependencies": { - "event-target-shim": "^6.0.2" + "event-target-shim": "^6.0.2", + "@bacons/text-decoder": "^0.0.0", + "web-streams-polyfill": "^4.0.0" }, "devDependencies": { "nitro-codegen": "^0.15.0", diff --git a/packages/react-native-fast-io/src/w3c/blob.ts b/packages/react-native-fast-io/src/w3c/blob.ts index ff3e6ac..a712091 100644 --- a/packages/react-native-fast-io/src/w3c/blob.ts +++ b/packages/react-native-fast-io/src/w3c/blob.ts @@ -1,3 +1,6 @@ +import { ReadableStream } from './streams' +import { TextDecoder } from './text' + export class Blob implements globalThis.Blob { private parts: Array diff --git a/packages/react-native-fast-io/src/w3c/fetch.ts b/packages/react-native-fast-io/src/w3c/fetch.ts index 3bf81ec..43f8c85 100644 --- a/packages/react-native-fast-io/src/w3c/fetch.ts +++ b/packages/react-native-fast-io/src/w3c/fetch.ts @@ -1,6 +1,7 @@ import { Network, RequestMethod } from '../native/network.nitro' import { Blob } from './blob' -import { fromReadableStream } from './streams' +import { File } from './fs' +import { fromReadableStream, ReadableStream } from './streams' export function fetch( url: string, diff --git a/packages/react-native-fast-io/src/w3c/streams.ts b/packages/react-native-fast-io/src/w3c/streams.ts index 36d6e47..2e7ea72 100644 --- a/packages/react-native-fast-io/src/w3c/streams.ts +++ b/packages/react-native-fast-io/src/w3c/streams.ts @@ -1,3 +1,5 @@ +import { ReadableStream, TransformStream, WritableStream } from 'web-streams-polyfill' + import { CompressorFactory, DuplexStream, InputStream, OutputStream } from '../native/streams.nitro' export const toReadableStream = (inputStream: InputStream) => { @@ -76,3 +78,5 @@ export class CompressionStream implements globalThis.CompressionStream { this.writable = writable } } + +export { ReadableStream, TransformStream, WritableStream } diff --git a/packages/react-native-fast-io/src/w3c/text.ts b/packages/react-native-fast-io/src/w3c/text.ts new file mode 100644 index 0000000..34d709c --- /dev/null +++ b/packages/react-native-fast-io/src/w3c/text.ts @@ -0,0 +1,3 @@ +export { TextDecoder } from '@bacons/text-decoder' + +export const TextEncoder = globalThis.TextEncoder