├── .eslintrc.js ├── .gitignore ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docs ├── blob.md ├── fetch.md ├── fs.md ├── streams.md └── ws.md ├── example ├── android │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── nitroplayground │ │ │ │ ├── MainActivity.kt │ │ │ │ └── MainApplication.kt │ │ │ └── res │ │ │ ├── drawable │ │ │ └── rn_edit_text_material.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── babel.config.js ├── index.js ├── ios │ ├── .xcode.env │ ├── NitroPlayground.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── NitroPlayground.xcscheme │ ├── NitroPlayground.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── NitroPlayground │ │ ├── AppDelegate.h │ │ ├── AppDelegate.mm │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ ├── PrivacyInfo.xcprivacy │ │ └── main.m │ ├── Podfile │ └── Podfile.lock ├── metro.config.js ├── package.json ├── react-native.config.js ├── server │ ├── createServer.ts │ ├── img.jpg │ ├── index.ts │ └── payloads.ts ├── tests │ ├── benchmark.tsx │ ├── filesystem.tsx │ └── index.tsx └── tsconfig.json ├── package-lock.json ├── package.json ├── packages └── react-native-fast-io │ ├── FastIO.podspec │ ├── README.md │ ├── android │ ├── CMakeLists.txt │ ├── build.gradle │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── cpp │ │ ├── HybridStreamFactory.cpp │ │ └── cpp-adapter.cpp │ │ └── java │ │ └── com │ │ └── margelo │ │ └── nitro │ │ └── fastio │ │ ├── FastIOPackage.java │ │ ├── HybridDuplexStream.kt │ │ ├── HybridFileSystem.kt │ │ ├── HybridInputStream.kt │ │ ├── HybridNetwork.kt │ │ ├── HybridOutputStream.kt │ │ ├── HybridStreamFactory.kt │ │ ├── HybridWebSocket.kt │ │ └── HybridWebSocketManager.kt │ ├── cpp │ ├── Constants.h │ ├── HybridCompressor.cpp │ ├── HybridCompressor.hpp │ ├── HybridCompressorFactory.cpp │ └── HybridCompressorFactory.hpp │ ├── ios │ ├── BridgingHeader.h │ ├── FastIOPrivate │ │ └── module.modulemap │ ├── HybridDuplexStream.swift │ ├── HybridFileSystem.swift │ ├── HybridInputStream.swift │ ├── HybridNetwork.swift │ ├── HybridOutputStream.swift │ ├── HybridStreamFactory.swift │ ├── HybridWebSocket.swift │ ├── HybridWebSocketManager.swift │ ├── WebSocketDelegate.swift │ └── WebSocketStream.swift │ ├── nitro.json │ ├── nitrogen │ └── generated │ │ ├── android │ │ ├── FastIO+autolinking.cmake │ │ ├── FastIO+autolinking.gradle │ │ ├── FastIOOnLoad.cpp │ │ ├── FastIOOnLoad.hpp │ │ ├── FastIOOnLoad.kt │ │ ├── c++ │ │ │ ├── JFunc_void_double_std__string.hpp │ │ │ ├── JFunc_void_std__shared_ptr_ArrayBuffer_.hpp │ │ │ ├── JFunc_void_std__string.hpp │ │ │ ├── JHybridDuplexStreamSpec.cpp │ │ │ ├── JHybridDuplexStreamSpec.hpp │ │ │ ├── JHybridFileSystemSpec.cpp │ │ │ ├── JHybridFileSystemSpec.hpp │ │ │ ├── JHybridInputStreamSpec.cpp │ │ │ ├── JHybridInputStreamSpec.hpp │ │ │ ├── JHybridNetworkSpec.cpp │ │ │ ├── JHybridNetworkSpec.hpp │ │ │ ├── JHybridOutputStreamSpec.cpp │ │ │ ├── JHybridOutputStreamSpec.hpp │ │ │ ├── JHybridStreamFactorySpec.cpp │ │ │ ├── JHybridStreamFactorySpec.hpp │ │ │ ├── JHybridWebSocketManagerSpec.cpp │ │ │ ├── JHybridWebSocketManagerSpec.hpp │ │ │ ├── JHybridWebSocketSpec.cpp │ │ │ ├── JHybridWebSocketSpec.hpp │ │ │ ├── JMetadata.hpp │ │ │ ├── JNativeFilePickerOptions.hpp │ │ │ ├── JRequestMethod.hpp │ │ │ ├── JRequestOptions.hpp │ │ │ └── JWellKnownDirectory.hpp │ │ └── kotlin │ │ │ └── com │ │ │ └── margelo │ │ │ └── nitro │ │ │ └── fastio │ │ │ ├── Func_void_double_std__string.kt │ │ │ ├── Func_void_std__shared_ptr_ArrayBuffer_.kt │ │ │ ├── Func_void_std__string.kt │ │ │ ├── HybridDuplexStreamSpec.kt │ │ │ ├── HybridFileSystemSpec.kt │ │ │ ├── HybridInputStreamSpec.kt │ │ │ ├── HybridNetworkSpec.kt │ │ │ ├── HybridOutputStreamSpec.kt │ │ │ ├── HybridStreamFactorySpec.kt │ │ │ ├── HybridWebSocketManagerSpec.kt │ │ │ ├── HybridWebSocketSpec.kt │ │ │ ├── Metadata.kt │ │ │ ├── NativeFilePickerOptions.kt │ │ │ ├── RequestMethod.kt │ │ │ ├── RequestOptions.kt │ │ │ └── WellKnownDirectory.kt │ │ ├── ios │ │ ├── FastIO+autolinking.rb │ │ ├── FastIO-Swift-Cxx-Bridge.cpp │ │ ├── FastIO-Swift-Cxx-Bridge.hpp │ │ ├── FastIO-Swift-Cxx-Umbrella.hpp │ │ ├── FastIOAutolinking.mm │ │ ├── FastIOAutolinking.swift │ │ ├── c++ │ │ │ ├── HybridDuplexStreamSpecSwift.cpp │ │ │ ├── HybridDuplexStreamSpecSwift.hpp │ │ │ ├── HybridFileSystemSpecSwift.cpp │ │ │ ├── HybridFileSystemSpecSwift.hpp │ │ │ ├── HybridInputStreamSpecSwift.cpp │ │ │ ├── HybridInputStreamSpecSwift.hpp │ │ │ ├── HybridNetworkSpecSwift.cpp │ │ │ ├── HybridNetworkSpecSwift.hpp │ │ │ ├── HybridOutputStreamSpecSwift.cpp │ │ │ ├── HybridOutputStreamSpecSwift.hpp │ │ │ ├── HybridStreamFactorySpecSwift.cpp │ │ │ ├── HybridStreamFactorySpecSwift.hpp │ │ │ ├── HybridWebSocketManagerSpecSwift.cpp │ │ │ ├── HybridWebSocketManagerSpecSwift.hpp │ │ │ ├── HybridWebSocketSpecSwift.cpp │ │ │ └── HybridWebSocketSpecSwift.hpp │ │ └── swift │ │ │ ├── Func_void.swift │ │ │ ├── Func_void_double_std__string.swift │ │ │ ├── Func_void_std__exception_ptr.swift │ │ │ ├── Func_void_std__shared_ptr_ArrayBuffer_.swift │ │ │ ├── Func_void_std__string.swift │ │ │ ├── Func_void_std__vector_std__string_.swift │ │ │ ├── HybridDuplexStreamSpec.swift │ │ │ ├── HybridDuplexStreamSpec_cxx.swift │ │ │ ├── HybridFileSystemSpec.swift │ │ │ ├── HybridFileSystemSpec_cxx.swift │ │ │ ├── HybridInputStreamSpec.swift │ │ │ ├── HybridInputStreamSpec_cxx.swift │ │ │ ├── HybridNetworkSpec.swift │ │ │ ├── HybridNetworkSpec_cxx.swift │ │ │ ├── HybridOutputStreamSpec.swift │ │ │ ├── HybridOutputStreamSpec_cxx.swift │ │ │ ├── HybridStreamFactorySpec.swift │ │ │ ├── HybridStreamFactorySpec_cxx.swift │ │ │ ├── HybridWebSocketManagerSpec.swift │ │ │ ├── HybridWebSocketManagerSpec_cxx.swift │ │ │ ├── HybridWebSocketSpec.swift │ │ │ ├── HybridWebSocketSpec_cxx.swift │ │ │ ├── Metadata.swift │ │ │ ├── NativeFilePickerOptions.swift │ │ │ ├── RequestMethod.swift │ │ │ ├── RequestOptions.swift │ │ │ └── WellKnownDirectory.swift │ │ └── shared │ │ └── c++ │ │ ├── CompressionAlgorithm.hpp │ │ ├── HybridCompressorFactorySpec.cpp │ │ ├── HybridCompressorFactorySpec.hpp │ │ ├── HybridCompressorSpec.cpp │ │ ├── HybridCompressorSpec.hpp │ │ ├── HybridDuplexStreamSpec.cpp │ │ ├── HybridDuplexStreamSpec.hpp │ │ ├── HybridFileSystemSpec.cpp │ │ ├── HybridFileSystemSpec.hpp │ │ ├── HybridInputStreamSpec.cpp │ │ ├── HybridInputStreamSpec.hpp │ │ ├── HybridNetworkSpec.cpp │ │ ├── HybridNetworkSpec.hpp │ │ ├── HybridOutputStreamSpec.cpp │ │ ├── HybridOutputStreamSpec.hpp │ │ ├── HybridStreamFactorySpec.cpp │ │ ├── HybridStreamFactorySpec.hpp │ │ ├── HybridWebSocketManagerSpec.cpp │ │ ├── HybridWebSocketManagerSpec.hpp │ │ ├── HybridWebSocketSpec.cpp │ │ ├── HybridWebSocketSpec.hpp │ │ ├── Metadata.hpp │ │ ├── NativeFilePickerOptions.hpp │ │ ├── RequestMethod.hpp │ │ ├── RequestOptions.hpp │ │ └── WellKnownDirectory.hpp │ ├── package.json │ ├── src │ ├── index.ts │ ├── native │ │ ├── fs.nitro.ts │ │ ├── network.nitro.ts │ │ ├── streams.nitro.ts │ │ └── ws.nitro.ts │ ├── types │ │ └── fs.ts │ └── w3c │ │ ├── blob.ts │ │ ├── fetch.ts │ │ ├── fs.ts │ │ ├── streams.ts │ │ ├── text.ts │ │ └── ws.ts │ └── tsconfig.json └── tsconfig.json /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | es6: true, 4 | node: true, 5 | }, 6 | plugins: ['import', 'simple-import-sort'], 7 | extends: ['eslint:recommended'], 8 | parserOptions: { 9 | ecmaVersion: 2020, 10 | sourceType: 'module', 11 | }, 12 | rules: { 13 | 'prettier/prettier': [ 14 | 'error', 15 | { 16 | trailingComma: 'es5', 17 | semi: false, 18 | singleQuote: true, 19 | arrowParens: 'always', 20 | printWidth: 100, 21 | }, 22 | ], 23 | 'object-shorthand': ['error', 'always'], 24 | 'simple-import-sort/imports': 'error', 25 | 'simple-import-sort/exports': 'error', 26 | }, 27 | overrides: [ 28 | { 29 | files: ['*.ts', '*.tsx'], 30 | parser: '@typescript-eslint/parser', 31 | plugins: ['@typescript-eslint/eslint-plugin'], 32 | extends: ['plugin:@typescript-eslint/recommended', 'plugin:import/typescript'], 33 | settings: { 34 | 'import/parsers': { 35 | '@typescript-eslint/parser': ['.ts', '.tsx'], 36 | }, 37 | 'import/resolver': { 38 | typescript: { 39 | alwaysTryTypes: true, 40 | }, 41 | }, 42 | }, 43 | rules: { 44 | '@typescript-eslint/no-explicit-any': 'off', 45 | '@typescript-eslint/ban-types': 'off', 46 | '@typescript-eslint/ban-ts-comment': 'off', 47 | '@typescript-eslint/ban-ts-ignore': 'off', 48 | '@typescript-eslint/explicit-module-boundary-types': 'off', 49 | '@typescript-eslint/explicit-function-return-type': 'off', 50 | }, 51 | }, 52 | { 53 | files: ['*'], 54 | plugins: ['prettier'], 55 | extends: ['plugin:prettier/recommended'], 56 | }, 57 | ], 58 | } 59 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Bun 6 | example/uploaded_file.jpg 7 | 8 | # Ruby 9 | vendor/ 10 | .bundle 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | **/.xcode.env.local 31 | 32 | # Android/IntelliJ 33 | # 34 | build/ 35 | .idea 36 | .gradle 37 | local.properties 38 | *.iml 39 | *.hprof 40 | .cxx/ 41 | *.keystore 42 | !debug.keystore 43 | 44 | # node.js 45 | # 46 | node_modules/ 47 | npm-debug.log 48 | yarn-error.log 49 | 50 | # fastlane 51 | # 52 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 53 | # screenshots whenever they are needed. 54 | # For more information about the recommended setup visit: 55 | # https://docs.fastlane.tools/best-practices/source-control/ 56 | 57 | **/fastlane/report.xml 58 | **/fastlane/Preview.html 59 | **/fastlane/screenshots 60 | **/fastlane/test_output 61 | 62 | # Bundle artifact 63 | *.jsbundle 64 | 65 | # Ruby / CocoaPods 66 | **/Pods/ 67 | /vendor/bundle/ 68 | 69 | # Temporary files created by Metro to check the health of the file watcher 70 | .metro-health-check* 71 | 72 | # Testing 73 | /coverage 74 | 75 | # Yarn 76 | .yarn/* 77 | !.yarn/patches 78 | !.yarn/plugins 79 | !.yarn/releases 80 | !.yarn/sdks 81 | !.yarn/versions 82 | 83 | # Builder Bob 84 | lib/ 85 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib", 3 | "typescript.enablePromptUseWorkspaceTsdk": true, 4 | "editor.formatOnSave": false, 5 | "editor.codeActionsOnSave": { 6 | "source.fixAll.eslint": "always" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We welcome contributions! Whether it's bug fixes, feature improvements, or documentation updates, your help is appreciated. 4 | 5 | This project follows the [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) Code of Conduct. By participating, you are expected to uphold this code. 6 | 7 | ## Commit Messages 8 | 9 | We use [Conventional Commits](https://www.conventionalcommits.org/) for clear communication and automated versioning. Please format your commit messages as follows: 10 | 11 | ``` 12 | type(scope): description 13 | 14 | [optional body] 15 | [optional footer] 16 | ``` 17 | 18 | Where `type` is one of: 19 | - `feat:` New features 20 | - `fix:` Bug fixes 21 | - `docs:` Documentation changes 22 | - `chore:` Maintenance tasks 23 | - `test:` Adding or updating tests 24 | - `refactor:` Code changes that neither fix bugs nor add features 25 | 26 | ## Development 27 | 28 | This library is built with [Nitro](https://mrousavy.github.io/nitro). After making changes to native code, you must run: 29 | 30 | ```bash 31 | npm run codegen 32 | ``` 33 | 34 | This regenerates the necessary bindings between JavaScript and native code. 35 | 36 | ## Working on the Example App 37 | 38 | Install dependencies: 39 | ```bash 40 | npm install 41 | ``` 42 | 43 | Then, follow these steps to run the app on iOS: 44 | ```bash 45 | cd ./example && npm run ios 46 | ``` 47 | 48 | or on Android: 49 | ```bash 50 | cd ./example && npm run android 51 | ``` 52 | 53 | You can also open the example project directly in Xcode (`example/ios/NitroPlayground.xcworkspace`) or Android Studio (`example/android`) for native development. 54 | 55 | Make sure to run the WebSocket server in the background: 56 | ```bash 57 | cd ./example && bun server.ts 58 | ``` 59 | 60 | Otherwise, the app will not be able to connect to the server and will fail with a connection error. 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Callstack 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

react-native-fast-io

3 |
4 | 5 |

6 | 7 |

8 | 9 |

10 | Your app, when you hit the Nitro boost 🏎️💨 11 |

12 | 13 | 14 | --- 15 | 16 | ## Getting started 17 | 18 | > [!WARNING] 19 | > This library is still under development. Use at your own risk. 20 | 21 | ``` 22 | npm install react-native-fast-io --save 23 | ``` 24 | 25 | ### Prerequisites 26 | 27 | - React Native 0.76 or higher 28 | - Nitro Modules 29 | 30 | ### Usage 31 | 32 | ```ts 33 | // With `unstable_enablePackageExports` enabled 34 | import { WebSocket } from 'react-native-fast-io/ws' 35 | 36 | // Otherwise 37 | import { WebSocket } from 'react-native-fast-io' 38 | ``` 39 | 40 | ## What's included 41 | 42 | | Name | Docs | W3C | Status | 43 | |------|------|-----|--------| 44 | | WebSocket | [📖](docs/ws.md) | [WebSocket API](https://websockets.spec.whatwg.org/) | Beta ✅ | 45 | | Fetch | [📖](docs/fetch.md) | [Fetch API](https://fetch.spec.whatwg.org/) | Work In Progress 🚧 | 46 | | FileSystem | [📖](docs/fs.md) | [File System Access API](https://wicg.github.io/file-system-access/) | Work In Progress 🚧 | 47 | | Blob | [📖](docs/blob.md) | [Blob API](https://w3c.github.io/FileAPI/#blob-section) | Work In Progress 🚧 | 48 | | Streams | [📖](docs/streams.md) | [Streams API](https://streams.spec.whatwg.org/) | Work In Progress 🚧 | 49 | 50 | > [!TIP] 51 | > Unless otherwise specified, all methods work as per W3C specifications. For details, consult each module's documentation. 52 | 53 | ## Made with ❤️ at Callstack 54 | 55 | React Native FastIO is an open source project and will always remain free to use. If you think it's cool, please star it 🌟. [Callstack](https://callstack.com) is a group of React and React Native geeks, contact us at [hello@callstack.com](mailto:hello@callstack.com) if you need any help with these or just want to say hi! 56 | 57 | Like the project? ⚛️ [Join the team](https://callstack.com/careers/?utm_campaign=Senior_RN&utm_source=github&utm_medium=readme) who does amazing stuff for clients and drives React Native Open Source! 🔥 | 58 | -------------------------------------------------------------------------------- /docs/blob.md: -------------------------------------------------------------------------------- 1 | # Blob 2 | 3 | ## Usage 4 | 5 | [TBD] 6 | 7 | ## Differences with React Native's `Blob` 8 | 9 | - Can create `Blob`s from `ArrayBuffer`, `ArrayBufferView` too. With React Native, [you can only create Blob from string or another Blob](https://github.com/facebook/react-native/blob/af384a914a4e9ef6a5d25b00bc14b0483e5af879/packages/react-native/Libraries/Blob/BlobManager.js#L69-L73) 10 | - Each `Blob` has `text()`, `arrayBuffer()`, and `stream()` methods. With React Native, you can only access the contents of `Blob` via [custom `data` field](https://github.com/facebook/react-native/blob/af384a914a4e9ef6a5d25b00bc14b0483e5af879/packages/react-native/Libraries/Blob/Blob.js#L75-L82) 11 | - `Blob` does not depend on a native module. Uses `ArrayBuffer`s natively, thanks to Nitro Modules. With React Native, [Blob uses `RCTBlobManager` under the hood](https://github.com/facebook/react-native/blob/bd323929dc5be5666ee36043babec7d981a095dc/packages/react-native/Libraries/Blob/RCTBlobManager.h#L15) to create and hold references to the data. 12 | - `Blob` is automatically deallocated when no longer in use. [You don't have to `close()` it manually](https://github.com/facebook/react-native/blob/bd323929dc5be5666ee36043babec7d981a095dc/packages/react-native/Libraries/Blob/Blob.js#L122-L138) 13 | -------------------------------------------------------------------------------- /docs/fetch.md: -------------------------------------------------------------------------------- 1 | # Networking 2 | 3 | ## Usage 4 | 5 | [TBD] 6 | 7 | ## Differences with React Native's `fetch` 8 | 9 | [TBD] 10 | 11 | ## Differences with Expo's `fetch` 12 | 13 | [TBD] 14 | -------------------------------------------------------------------------------- /docs/fs.md: -------------------------------------------------------------------------------- 1 | # Fs 2 | 3 | ## Usage 4 | 5 | [TBD] 6 | 7 | ## Differences with `react-native-document-picker` 8 | 9 | [TBD] 10 | 11 | ## Differences with `expo-file-system` 12 | 13 | [TBD] 14 | -------------------------------------------------------------------------------- /docs/streams.md: -------------------------------------------------------------------------------- 1 | # Streams 2 | 3 | ## Usage 4 | 5 | [TBD] 6 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/nitroplayground/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.nitroplayground 2 | 3 | import com.facebook.react.ReactActivity 4 | import com.facebook.react.ReactActivityDelegate 5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled 6 | import com.facebook.react.defaults.DefaultReactActivityDelegate 7 | 8 | class MainActivity : ReactActivity() { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | override fun getMainComponentName(): String = "NitroPlayground" 15 | 16 | /** 17 | * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] 18 | * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] 19 | */ 20 | override fun createReactActivityDelegate(): ReactActivityDelegate = 21 | DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) 22 | } 23 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/nitroplayground/MainApplication.kt: -------------------------------------------------------------------------------- 1 | package com.nitroplayground 2 | 3 | import android.app.Application 4 | import com.facebook.react.PackageList 5 | import com.facebook.react.ReactApplication 6 | import com.facebook.react.ReactHost 7 | import com.facebook.react.ReactNativeHost 8 | import com.facebook.react.ReactPackage 9 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load 10 | import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost 11 | import com.facebook.react.soloader.OpenSourceMergedSoMapping 12 | import com.facebook.react.defaults.DefaultReactNativeHost 13 | import com.facebook.soloader.SoLoader 14 | 15 | class MainApplication : Application(), ReactApplication { 16 | 17 | override val reactNativeHost: ReactNativeHost = 18 | object : DefaultReactNativeHost(this) { 19 | override fun getPackages(): List = 20 | PackageList(this).packages.apply { 21 | // Packages that cannot be autolinked yet can be added manually here, for example: 22 | // add(MyReactNativePackage()) 23 | } 24 | 25 | override fun getJSMainModuleName(): String = "index" 26 | 27 | override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG 28 | 29 | override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED 30 | override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED 31 | } 32 | 33 | override val reactHost: ReactHost 34 | get() = getDefaultReactHost(applicationContext, reactNativeHost) 35 | 36 | override fun onCreate() { 37 | super.onCreate() 38 | SoLoader.init(this, OpenSourceMergedSoMapping) 39 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 40 | // If you opted-in for the New Architecture, we load the native entry point for this app. 41 | load() 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 22 | 23 | 24 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | NitroPlayground 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | buildToolsVersion = "35.0.0" 4 | minSdkVersion = 24 5 | compileSdkVersion = 35 6 | targetSdkVersion = 34 7 | ndkVersion = "26.1.10909125" 8 | kotlinVersion = "1.9.24" 9 | } 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | dependencies { 15 | classpath("com.android.tools.build:gradle") 16 | classpath("com.facebook.react:react-native-gradle-plugin") 17 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") 18 | } 19 | } 20 | 21 | apply plugin: "com.facebook.react.rootproject" 22 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | 25 | # Use this property to specify which architecture you want to build. 26 | # You can also override it from the CLI using 27 | # ./gradlew -PreactNativeArchitectures=x86_64 28 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 29 | 30 | # Use this property to enable support to the new architecture. 31 | # This will allow you to use TurboModules and the Fabric render in 32 | # your application. You should enable this flag either if you want 33 | # to write custom TurboModules/Fabric components OR use libraries that 34 | # are providing them. 35 | newArchEnabled=true 36 | 37 | # Use this property to enable or disable the Hermes JS engine. 38 | # If set to false, you will be using JSC instead. 39 | hermesEnabled=true 40 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { includeBuild("../../node_modules/@react-native/gradle-plugin") } 2 | plugins { id("com.facebook.react.settings") } 3 | extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } 4 | 5 | rootProject.name = 'NitroPlayground' 6 | 7 | include ':app' 8 | includeBuild('../../node_modules/@react-native/gradle-plugin') -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:@react-native/babel-preset'], 3 | } 4 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import '@azure/core-asynciterator-polyfill' 2 | 3 | import { AppRegistry } from 'react-native' 4 | 5 | import { App } from './tests' 6 | 7 | AppRegistry.registerComponent('NitroPlayground', () => App) 8 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | export NODE_BINARY=$(command -v node) 2 | -------------------------------------------------------------------------------- /example/ios/NitroPlayground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/NitroPlayground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/NitroPlayground/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : RCTAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/ios/NitroPlayground/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | 5 | @implementation AppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 8 | { 9 | self.moduleName = @"NitroPlayground"; 10 | // You can add your custom initial props in the dictionary below. 11 | // They will be passed down to the ViewController used by React Native. 12 | self.initialProps = @{}; 13 | 14 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 15 | } 16 | 17 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 18 | { 19 | return [self bundleURL]; 20 | } 21 | 22 | - (NSURL *)bundleURL 23 | { 24 | #if DEBUG 25 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 26 | #else 27 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 28 | #endif 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /example/ios/NitroPlayground/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/ios/NitroPlayground/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/NitroPlayground/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | NitroPlayground 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(MARKETING_VERSION) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(CURRENT_PROJECT_VERSION) 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | 30 | NSAllowsArbitraryLoads 31 | 32 | NSAllowsLocalNetworking 33 | 34 | 35 | NSLocationWhenInUseUsageDescription 36 | 37 | UILaunchStoryboardName 38 | LaunchScreen 39 | UIRequiredDeviceCapabilities 40 | 41 | arm64 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | UIViewControllerBasedStatusBarAppearance 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /example/ios/NitroPlayground/PrivacyInfo.xcprivacy: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPrivacyAccessedAPITypes 6 | 7 | 8 | NSPrivacyAccessedAPIType 9 | NSPrivacyAccessedAPICategoryFileTimestamp 10 | NSPrivacyAccessedAPITypeReasons 11 | 12 | C617.1 13 | 14 | 15 | 16 | NSPrivacyAccessedAPIType 17 | NSPrivacyAccessedAPICategoryUserDefaults 18 | NSPrivacyAccessedAPITypeReasons 19 | 20 | CA92.1 21 | 22 | 23 | 24 | NSPrivacyAccessedAPIType 25 | NSPrivacyAccessedAPICategorySystemBootTime 26 | NSPrivacyAccessedAPITypeReasons 27 | 28 | 35F9.1 29 | 30 | 31 | 32 | NSPrivacyCollectedDataTypes 33 | 34 | NSPrivacyTracking 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/NitroPlayground/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Resolve react_native_pods.rb with node to allow for hoisting 2 | require Pod::Executable.execute_command('node', ['-p', 3 | 'require.resolve( 4 | "react-native/scripts/react_native_pods.rb", 5 | {paths: [process.argv[1]]}, 6 | )', __dir__]).strip 7 | 8 | platform :ios, min_ios_version_supported 9 | prepare_react_native_project! 10 | 11 | linkage = ENV['USE_FRAMEWORKS'] 12 | if linkage != nil 13 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green 14 | use_frameworks! :linkage => linkage.to_sym 15 | end 16 | 17 | target 'NitroPlayground' do 18 | config = use_native_modules! 19 | 20 | use_react_native!( 21 | :path => config[:reactNativePath], 22 | # An absolute path to your application root. 23 | :app_path => "#{Pod::Config.instance.installation_root}/.." 24 | ) 25 | 26 | target 'NitroPlaygroundTests' do 27 | inherit! :complete 28 | # Pods for testing 29 | end 30 | 31 | post_install do |installer| 32 | # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 33 | react_native_post_install( 34 | installer, 35 | config[:reactNativePath], 36 | :mac_catalyst_enabled => false, 37 | # :ccache_enabled => true 38 | ) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config') 2 | const path = require('path') 3 | const root = path.resolve(__dirname, '..') 4 | 5 | /** 6 | * Metro configuration 7 | * https://facebook.github.io/metro/docs/configuration 8 | * 9 | * @type {import('metro-config').MetroConfig} 10 | */ 11 | const config = { 12 | watchFolders: [root], 13 | resolver: { 14 | unstable_enablePackageExports: true, 15 | }, 16 | } 17 | 18 | module.exports = mergeConfig(getDefaultConfig(__dirname), config) 19 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@react-native-module/app", 3 | "version": "0.0.1", 4 | "scripts": { 5 | "android": "react-native run-android", 6 | "ios": "react-native run-ios", 7 | "start": "react-native start", 8 | "server": "bun server/index.ts" 9 | }, 10 | "dependencies": { 11 | "@azure/core-asynciterator-polyfill": "^1.0.2", 12 | "cli-table3": "^0.6.5", 13 | "react": "18.3.1", 14 | "react-native": "0.76.0", 15 | "react-native-nitro-modules": "^0.20.0" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "^7.20.0", 19 | "@babel/preset-env": "^7.20.0", 20 | "@babel/runtime": "^7.20.0", 21 | "@react-native-community/cli": "^15.0.1", 22 | "@react-native-community/cli-platform-android": "^15.0.1", 23 | "@react-native-community/cli-platform-ios": "^15.0.1", 24 | "@react-native/babel-preset": "0.76.0", 25 | "@react-native/metro-config": "0.76.0", 26 | "@types/react": "^18.2.6", 27 | "eslint": "^8.19.0" 28 | }, 29 | "engines": { 30 | "node": ">=18" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /example/react-native.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pkg = require('../packages/react-native-fast-io/package.json') 3 | 4 | module.exports = { 5 | project: { 6 | ios: { 7 | automaticPodsInstallation: true, 8 | }, 9 | }, 10 | dependencies: { 11 | [pkg.name]: { 12 | root: path.join(__dirname, '..', 'packages', 'react-native-fast-io'), 13 | }, 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /example/server/createServer.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | /** 4 | * Creates a WebSocket server that sends configurable responses and handles file uploads 5 | */ 6 | export function createServer(payload: string | Bun.BufferSource, port: number) { 7 | const server = Bun.serve({ 8 | async fetch(req, server) { 9 | // Handle WebSocket upgrade 10 | if (server.upgrade(req)) { 11 | return 12 | } 13 | 14 | // Handle POST /upload 15 | if (req.method === 'POST' && req.url.endsWith('/upload')) { 16 | try { 17 | console.log('Waiting for body...') 18 | 19 | if (!req.body) { 20 | return new Response('No body provided', { status: 400 }) 21 | } 22 | 23 | const writer = Bun.file('uploaded_file.jpg.gz').writer() 24 | 25 | for await (const chunk of req.body) { 26 | // Write each chunk to file 27 | writer.write(chunk) 28 | // Debug 29 | console.log('Chunk saved:', chunk.length, 'bytes') 30 | } 31 | 32 | await writer.end() 33 | 34 | console.log('Upload complete, file saved') 35 | 36 | return new Response('Upload successful', { status: 200 }) 37 | } catch (error) { 38 | console.error('Upload error:', error) 39 | return new Response('Upload failed', { status: 500 }) 40 | } 41 | } 42 | 43 | // Default response for other routes 44 | return new Response('Not found', { status: 404 }) 45 | }, 46 | websocket: { 47 | message(ws, message: string) { 48 | if (typeof message !== 'string') { 49 | return 50 | } 51 | const count = parseInt(message) 52 | if (isNaN(count)) { 53 | return 54 | } 55 | try { 56 | for (let i = 0; i < count; i++) { 57 | ws.send(payload) 58 | } 59 | } catch (error) { 60 | console.error('Failed to parse message:', error) 61 | } 62 | }, 63 | }, 64 | port, 65 | }) 66 | 67 | console.log(`Server listening on http://localhost:${port}`) 68 | 69 | // Return cleanup function 70 | return () => server.stop() 71 | } 72 | -------------------------------------------------------------------------------- /example/server/img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/react-native-fast-io/dbe588be96dcd16913d8fad68cc6ad6b3a54d69e/example/server/img.jpg -------------------------------------------------------------------------------- /example/server/index.ts: -------------------------------------------------------------------------------- 1 | import { createServer } from './createServer' 2 | import { 3 | CHAT_PAYLOAD, 4 | CHAT_PAYLOAD_BINARY, 5 | CHAT_SERVER_BINARY_PORT, 6 | CHAT_SERVER_PORT, 7 | COORDINATE_PAYLOAD, 8 | COORDINATE_PAYLOAD_BINARY, 9 | COORDINATE_SERVER_BINARY_PORT, 10 | COORDINATE_SERVER_PORT, 11 | IMAGE_SERVER_PORT, 12 | } from './payloads' 13 | 14 | async function run() { 15 | const stopChatServer = createServer(CHAT_PAYLOAD, CHAT_SERVER_PORT) 16 | const stopChatBinaryServer = createServer(CHAT_PAYLOAD_BINARY, CHAT_SERVER_BINARY_PORT) 17 | const stopCoordinateServer = createServer(COORDINATE_PAYLOAD, COORDINATE_SERVER_PORT) 18 | const stopCoordinateBinaryServer = createServer( 19 | COORDINATE_PAYLOAD_BINARY, 20 | COORDINATE_SERVER_BINARY_PORT 21 | ) 22 | const stopImageServer = createServer( 23 | await Bun.file(__dirname + '/img.jpg').arrayBuffer(), 24 | IMAGE_SERVER_PORT 25 | ) 26 | 27 | const stopAllServers = () => { 28 | stopChatServer() 29 | stopChatBinaryServer() 30 | stopCoordinateServer() 31 | stopCoordinateBinaryServer() 32 | stopImageServer() 33 | } 34 | 35 | process.on('SIGINT', () => { 36 | stopAllServers() 37 | process.exit(0) 38 | }) 39 | } 40 | 41 | run() 42 | -------------------------------------------------------------------------------- /example/server/payloads.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file contains the payloads that are used in the test. 3 | */ 4 | 5 | const encoder = new TextEncoder() 6 | 7 | export const CHAT_PAYLOAD = JSON.stringify({ 8 | id: '123e4567-e89b-12d3-a456-426614174000', 9 | type: 'message', 10 | content: { 11 | text: 'Hello! How are you doing today? 👋', 12 | mentions: ['@mike'], 13 | attachments: [], 14 | }, 15 | room: { 16 | id: 'room_456', 17 | type: 'direct', 18 | }, 19 | metadata: { 20 | client: 'react-native-fast-io/1.0.0', 21 | }, 22 | }) 23 | 24 | export const CHAT_PAYLOAD_BINARY = encoder.encode(JSON.stringify(CHAT_PAYLOAD)) 25 | 26 | export const COORDINATE_PAYLOAD = JSON.stringify({ 27 | coords: [456, 750], 28 | }) 29 | export const COORDINATE_PAYLOAD_BINARY = encoder.encode(JSON.stringify(COORDINATE_PAYLOAD)) 30 | 31 | export const CHAT_SERVER_PORT = 3000 32 | export const CHAT_SERVER_BINARY_PORT = 3001 33 | 34 | export const COORDINATE_SERVER_PORT = 3002 35 | export const COORDINATE_SERVER_BINARY_PORT = 3003 36 | 37 | export const IMAGE_SERVER_PORT = 3004 38 | -------------------------------------------------------------------------------- /example/tests/index.tsx: -------------------------------------------------------------------------------- 1 | import { SafeAreaView, ScrollView } from 'react-native' 2 | 3 | import { BenchmarkUI } from './benchmark' 4 | import { FileSystemUI } from './filesystem' 5 | 6 | export function App() { 7 | return ( 8 | 9 | 10 | 11 | 12 | 13 | 14 | ) 15 | } 16 | -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "..", 3 | "compilerOptions": { 4 | "resolvePackageJsonExports": false, 5 | "paths": { 6 | "react-native-fast-io": ["../packages/react-native-fast-io/src/index.ts"], 7 | "react-native-fast-io/*": ["../packages/react-native-fast-io/src/w3c/*"] 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-module", 3 | "private": true, 4 | "license": "MIT", 5 | "workspaces": [ 6 | "./packages/*", 7 | "./example" 8 | ], 9 | "scripts": { 10 | "codegen": "(cd ./packages/react-native-fast-io && npm run codegen) && (cd ./example/ios && pod install) && (cd ./example/android && ./gradlew clean && ./gradlew build)", 11 | "test": "vitest", 12 | "release": "release-it" 13 | }, 14 | "devDependencies": { 15 | "@react-native/typescript-config": "0.75.3", 16 | "@release-it-plugins/workspaces": "^4.2.0", 17 | "@release-it/conventional-changelog": "^9.0.3", 18 | "@types/jest": "^29.5.13", 19 | "@types/tar": "^6.1.13", 20 | "@typescript-eslint/eslint-plugin": "^7.3.1", 21 | "@typescript-eslint/parser": "^7.3.1", 22 | "bun-types": "^1.1.33", 23 | "eslint": "^8.21.0", 24 | "eslint-config-prettier": "^9.1.0", 25 | "eslint-plugin-import": "^2.29.1", 26 | "eslint-plugin-prettier": "^5.0.0", 27 | "eslint-plugin-simple-import-sort": "^12.0.0", 28 | "prettier": "^3.2.5", 29 | "release-it": "^17.10.0", 30 | "typescript": "^5.1.3", 31 | "vitest": "^2.1.1" 32 | }, 33 | "overrides": { 34 | "cross-spawn": "7.0.5" 35 | }, 36 | "release-it": { 37 | "git": { 38 | "commitMessage": "chore: release ${version}", 39 | "tagName": "v${version}" 40 | }, 41 | "npm": false, 42 | "plugins": { 43 | "@release-it/conventional-changelog": { 44 | "preset": "angular" 45 | }, 46 | "@release-it-plugins/workspaces": { 47 | "workspaces": [ 48 | "packages/*" 49 | ], 50 | "additionalManifests": { 51 | "dependencyUpdates": [ 52 | "example/*/package.json" 53 | ] 54 | } 55 | } 56 | } 57 | }, 58 | "version": "0.2.0" 59 | } 60 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/FastIO.podspec: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, "package.json"))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = "FastIO" 7 | s.version = package["version"] 8 | s.summary = package["description"] 9 | s.homepage = package["homepage"] 10 | s.license = package["license"] 11 | s.authors = package["author"] 12 | 13 | s.platforms = { :ios => min_ios_version_supported } 14 | s.source = { :git => "https://github.com/grabbou/react-native-fast-io.git", :tag => "#{s.version}" } 15 | 16 | s.source_files = [ 17 | "ios/**/*.{h,m,swift}", 18 | "cpp/**/*.{h,hpp,cpp}" 19 | ] 20 | 21 | s.pod_target_xcconfig = { 22 | 'SWIFT_INCLUDE_PATHS' => '$(PODS_TARGET_SRCROOT)/ios' 23 | } 24 | 25 | load 'nitrogen/generated/ios/FastIO+autolinking.rb' 26 | add_nitrogen_files(s) 27 | 28 | install_modules_dependencies(s) 29 | end 30 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/README.md: -------------------------------------------------------------------------------- 1 |
2 |

react-native-fast-io

3 |
4 | 5 |

6 | 7 |

8 | 9 |

10 | Your app, when you hit the Nitro boost 🏎️💨 11 |

12 | 13 | 14 | --- 15 | 16 | Thank you for using `react-native-fast-io`! To learn more, check our [documentation](https://github.com/callstackincubator/react-native-fast-ws/tree/main/docs). 17 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(FastIO) 2 | cmake_minimum_required(VERSION 3.9.0) 3 | 4 | set (PACKAGE_NAME FastIO) 5 | set (CMAKE_VERBOSE_MAKEFILE ON) 6 | set (CMAKE_CXX_STANDARD 20) 7 | 8 | # Define C++ library and add all sources 9 | add_library(${PACKAGE_NAME} SHARED 10 | src/main/cpp/cpp-adapter.cpp 11 | src/main/cpp/HybridStreamFactory.cpp 12 | ../cpp/HybridCompressor.cpp 13 | ../cpp/HybridCompressorFactory.cpp 14 | ) 15 | 16 | # Add Nitrogen specs :) 17 | include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/FastIO+autolinking.cmake) 18 | 19 | # Set up local includes 20 | include_directories( 21 | "src/main/cpp" 22 | "../cpp" 23 | ) 24 | 25 | find_package(ZLIB REQUIRED) 26 | find_library(LOG_LIB log) 27 | 28 | # Link all libraries together 29 | target_link_libraries( 30 | ${PACKAGE_NAME} 31 | ${LOG_LIB} 32 | ${ZLIB_LIBRARIES} 33 | android # <-- Android core 34 | ) 35 | 36 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/cpp/HybridStreamFactory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Constants.h" 3 | 4 | extern "C" 5 | JNIEXPORT jint JNICALL 6 | Java_com_margelo_nitro_fastio_HybridStreamFactory_getBufferSize( 7 | JNIEnv* env, 8 | jclass /* this */ 9 | ) { 10 | return FASTIO_BUFFER_SIZE; 11 | } 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/cpp/cpp-adapter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "FastIOOnLoad.hpp" 5 | 6 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) { 7 | return facebook::jni::initialize(vm, [=] { margelo::nitro::fastio::initialize(vm); }); 8 | } 9 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/java/com/margelo/nitro/fastio/FastIOPackage.java: -------------------------------------------------------------------------------- 1 | package com.margelo.nitro.fastio; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.annotation.Nullable; 5 | 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.module.model.ReactModuleInfoProvider; 9 | import com.facebook.react.TurboReactPackage; 10 | 11 | import java.util.HashMap; 12 | 13 | public class FastIOPackage extends TurboReactPackage { 14 | @Nullable 15 | @Override 16 | public NativeModule getModule(@NonNull String name, @NonNull ReactApplicationContext reactContext) { 17 | return null; 18 | } 19 | 20 | @Override 21 | public ReactModuleInfoProvider getReactModuleInfoProvider() { 22 | return HashMap::new; 23 | } 24 | 25 | static { 26 | System.loadLibrary("FastIO"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/java/com/margelo/nitro/fastio/HybridDuplexStream.kt: -------------------------------------------------------------------------------- 1 | package com.margelo.nitro.fastio 2 | 3 | import java.io.PipedInputStream 4 | import java.io.PipedOutputStream 5 | 6 | class HybridDuplexStream : HybridDuplexStreamSpec() { 7 | private val pipeIn = PipedInputStream(HybridStreamFactory.BUFFER_SIZE) 8 | private val pipeOut = PipedOutputStream(pipeIn) 9 | 10 | override var inputStream: HybridInputStreamSpec = HybridInputStream(pipeIn).also { 11 | System.err.println("Created input stream wrapper") 12 | } 13 | 14 | override var outputStream: HybridOutputStreamSpec = HybridOutputStream(pipeOut).also { 15 | System.err.println("Created output stream wrapper") 16 | } 17 | 18 | override val memorySize: Long = 0L 19 | 20 | fun close() { 21 | try { 22 | System.err.println("Closing duplex stream") 23 | pipeOut.close() 24 | pipeIn.close() 25 | } catch (e: Exception) { 26 | System.err.println("Error closing duplex stream: ${e.message}") 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/java/com/margelo/nitro/fastio/HybridInputStream.kt: -------------------------------------------------------------------------------- 1 | package com.margelo.nitro.fastio 2 | 3 | import com.margelo.nitro.core.ArrayBuffer 4 | import com.margelo.nitro.core.Promise 5 | import kotlinx.coroutines.CoroutineScope 6 | import kotlinx.coroutines.Dispatchers 7 | import java.io.InputStream 8 | 9 | class HybridInputStream(val stream: InputStream) : HybridInputStreamSpec() { 10 | override fun read(): Promise { 11 | return Promise.async(CoroutineScope(Dispatchers.IO)) { 12 | val bytes = ByteArray(HybridStreamFactory.BUFFER_SIZE) 13 | val bytesRead = stream.read(bytes, 0, bytes.size) 14 | 15 | when { 16 | bytesRead == -1 -> { 17 | val emptyBuffer = ArrayBuffer.allocate(0) 18 | emptyBuffer 19 | } 20 | bytesRead > 0 -> { 21 | val arrayBuffer = ArrayBuffer.allocate(bytesRead) 22 | val destBuffer = arrayBuffer.getBuffer(false) 23 | destBuffer.put(bytes, 0, bytesRead) 24 | arrayBuffer 25 | } 26 | else -> { 27 | throw Error("Unexpected error reading stream") 28 | } 29 | } 30 | } 31 | } 32 | 33 | override fun open() { 34 | // No explicit open needed for Java InputStreams 35 | } 36 | 37 | override fun close() { 38 | stream.close() 39 | } 40 | 41 | override val memorySize: Long 42 | get() = try { 43 | stream.available().toLong() 44 | } catch (e: Exception) { 45 | 0L 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/java/com/margelo/nitro/fastio/HybridNetwork.kt: -------------------------------------------------------------------------------- 1 | package com.margelo.nitro.fastio 2 | 3 | import com.margelo.nitro.core.Promise 4 | import kotlinx.coroutines.CoroutineScope 5 | import kotlinx.coroutines.Dispatchers 6 | import java.net.HttpURLConnection 7 | import java.net.URL 8 | 9 | class HybridNetwork : HybridNetworkSpec() { 10 | override fun request(opts: RequestOptions): Promise { 11 | Promise.async(CoroutineScope(Dispatchers.IO)) { 12 | val connection = URL(opts.url).openConnection() as HttpURLConnection 13 | connection.apply { 14 | requestMethod = opts.method.name.uppercase() 15 | doInput = true 16 | doOutput = opts.body != null 17 | 18 | opts.body?.let { hybridStream -> 19 | (hybridStream as HybridInputStream).stream.use { input -> 20 | outputStream.buffered().use { output -> 21 | input.copyTo(output, HybridStreamFactory.BUFFER_SIZE) 22 | } 23 | } 24 | } 25 | 26 | if (responseCode !in 200..299) { 27 | throw Error("HTTP Error: $responseCode") 28 | } 29 | } 30 | } 31 | return Promise.resolved(Unit) 32 | } 33 | 34 | override val memorySize: Long 35 | get() = 0L 36 | } 37 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/java/com/margelo/nitro/fastio/HybridOutputStream.kt: -------------------------------------------------------------------------------- 1 | package com.margelo.nitro.fastio 2 | 3 | import com.margelo.nitro.core.ArrayBuffer 4 | import com.margelo.nitro.core.Promise 5 | import java.io.OutputStream 6 | 7 | class HybridOutputStream(private val stream: OutputStream) : HybridOutputStreamSpec() { 8 | override fun write(buffer: ArrayBuffer): Promise { 9 | val byteBuffer = buffer.getBuffer(false) 10 | val bytes = ByteArray(buffer.size) 11 | byteBuffer.get(bytes) 12 | 13 | return Promise.async { 14 | stream.write(bytes) 15 | } 16 | } 17 | 18 | override fun open() { 19 | // No explicit open needed for Java OutputStreams 20 | } 21 | 22 | override fun close() { 23 | try { 24 | stream.flush() 25 | stream.close() 26 | } catch (e: Exception) { 27 | println("Error closing stream: ${e.message}") 28 | } 29 | } 30 | 31 | override val memorySize: Long 32 | get() = 0L 33 | } 34 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/java/com/margelo/nitro/fastio/HybridStreamFactory.kt: -------------------------------------------------------------------------------- 1 | package com.margelo.nitro.fastio 2 | 3 | import android.net.Uri 4 | import com.margelo.nitro.NitroModules 5 | 6 | class HybridStreamFactory : HybridStreamFactorySpec() { 7 | override val bufferSize: Double 8 | get() = getBufferSize().toDouble() 9 | 10 | override fun createInputStream(path: String): HybridInputStreamSpec { 11 | val context = NitroModules.applicationContext 12 | ?: throw RuntimeException("Application context is missing") 13 | 14 | val uri = Uri.parse(path) 15 | val inputStream = context.contentResolver.openInputStream(uri) 16 | ?: throw RuntimeException("Cannot open stream for: $path") 17 | 18 | return HybridInputStream(inputStream) 19 | } 20 | 21 | override val memorySize: Long 22 | get() = 0L 23 | 24 | companion object { 25 | @JvmStatic 26 | val BUFFER_SIZE: Int = getBufferSize() 27 | 28 | @JvmStatic 29 | private external fun getBufferSize(): Int 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/android/src/main/java/com/margelo/nitro/fastio/HybridWebSocketManager.kt: -------------------------------------------------------------------------------- 1 | package com.margelo.nitro.fastio 2 | 3 | import com.facebook.proguard.annotations.DoNotStrip 4 | 5 | @DoNotStrip 6 | class HybridWebSocketManager : HybridWebSocketManagerSpec() { 7 | override fun create(url: String, protocols: Array): HybridWebSocketSpec { 8 | return HybridWebSocket(url, protocols) 9 | } 10 | 11 | override val memorySize: Long 12 | get() = 0L 13 | } 14 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/cpp/Constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #define FASTIO_BUFFER_SIZE (64 * 1024) 8 | 9 | #ifdef __cplusplus 10 | } 11 | #endif 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/cpp/HybridCompressor.cpp: -------------------------------------------------------------------------------- 1 | #include "HybridCompressor.hpp" 2 | #include 3 | #include 4 | 5 | namespace margelo::nitro::fastio { 6 | 7 | HybridCompressor::HybridCompressor(CompressionAlgorithm algorithm) : HybridObject(TAG) { 8 | std::cout << "Initializing compressor with algorithm: " << static_cast(algorithm) << std::endl; 9 | 10 | _stream.zalloc = Z_NULL; 11 | _stream.zfree = Z_NULL; 12 | _stream.opaque = Z_NULL; 13 | 14 | int windowBits = 15; 15 | switch (algorithm) { 16 | case CompressionAlgorithm::GZIP: 17 | windowBits += 16; 18 | break; 19 | case CompressionAlgorithm::DEFLATE_RAW: 20 | windowBits = -windowBits; 21 | break; 22 | default: 23 | break; 24 | } 25 | 26 | if (deflateInit2(&_stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, windowBits, 8, Z_DEFAULT_STRATEGY) != Z_OK) { 27 | throw std::runtime_error("Failed to initialize compression"); 28 | } 29 | } 30 | 31 | HybridCompressor::~HybridCompressor() { 32 | deflateEnd(&_stream); 33 | } 34 | 35 | std::shared_ptr HybridCompressor::compressBuffer(const uint8_t* source, size_t sourceSize, bool finalize) { 36 | uint8_t* destBuffer = new uint8_t[64 * 1024]; 37 | 38 | _stream.next_in = const_cast(source); 39 | _stream.avail_in = sourceSize; 40 | _stream.next_out = destBuffer; 41 | _stream.avail_out = 64 * 1024; 42 | 43 | int status = deflate(&_stream, finalize ? Z_FINISH : Z_NO_FLUSH); 44 | 45 | if (status == Z_STREAM_ERROR) { 46 | delete[] destBuffer; 47 | throw std::runtime_error("Compression error"); 48 | } 49 | 50 | if (_stream.avail_in != 0) { 51 | delete[] destBuffer; 52 | throw std::runtime_error("Unexpected remaining input data"); 53 | } 54 | 55 | size_t currentOffset = 64 * 1024 - _stream.avail_out; 56 | 57 | return ArrayBuffer::makeBuffer( 58 | destBuffer, 59 | currentOffset, 60 | [=] { delete[] destBuffer; } 61 | ); 62 | } 63 | 64 | std::shared_ptr HybridCompressor::compress(const std::shared_ptr& chunk) { 65 | return compressBuffer( 66 | chunk->data(), 67 | chunk->size() 68 | ); 69 | } 70 | 71 | std::shared_ptr HybridCompressor::finalize() { 72 | static const uint8_t dummyByte = 0; 73 | return compressBuffer(&dummyByte, 0, true); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/cpp/HybridCompressor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "HybridCompressorSpec.hpp" 8 | #include "CompressionAlgorithm.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | class HybridCompressor : public HybridCompressorSpec { 13 | public: 14 | explicit HybridCompressor(CompressionAlgorithm algorithm); 15 | ~HybridCompressor(); 16 | 17 | std::shared_ptr compress(const std::shared_ptr& chunk); 18 | std::shared_ptr finalize(); 19 | 20 | private: 21 | std::shared_ptr compressBuffer(const uint8_t* source, size_t sourceSize, bool finalize = false); 22 | 23 | z_stream _stream{}; 24 | }; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/cpp/HybridCompressorFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "HybridCompressorFactory.hpp" 2 | #include "HybridCompressor.hpp" 3 | #include 4 | 5 | namespace margelo::nitro::fastio { 6 | 7 | std::shared_ptr HybridCompressorFactory::create(CompressionAlgorithm algorithm) { 8 | return std::make_shared(algorithm); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/cpp/HybridCompressorFactory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "HybridCompressorFactorySpec.hpp" 5 | #include "HybridCompressor.hpp" 6 | 7 | namespace margelo::nitro::fastio { 8 | 9 | class HybridCompressorFactory : public HybridCompressorFactorySpec { 10 | public: 11 | HybridCompressorFactory() : HybridObject(TAG) {} 12 | 13 | std::shared_ptr create(CompressionAlgorithm algorithm) override; 14 | }; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/BridgingHeader.h: -------------------------------------------------------------------------------- 1 | #import 2 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/FastIOPrivate/module.modulemap: -------------------------------------------------------------------------------- 1 | module FastIOPrivate { 2 | header "../BridgingHeader.h" 3 | header "../../cpp/Constants.h" 4 | export * 5 | } 6 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/HybridDuplexStream.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HybridStreamManager.swift 3 | // FastIO 4 | // 5 | // Created by Mike Grabowski on 07/11/2024. 6 | // 7 | 8 | import Foundation 9 | 10 | class HybridDuplexStream : HybridDuplexStreamSpec { 11 | var inputStream: (any HybridInputStreamSpec) 12 | var outputStream: (any HybridOutputStreamSpec) 13 | 14 | override init() { 15 | var inputStreamRef: InputStream? = InputStream() 16 | var outputStreamRef: OutputStream? = OutputStream(toMemory: ()) 17 | 18 | Stream.getBoundStreams(withBufferSize: Int(HybridStreamFactory.BUFFER_SIZE), inputStream: &inputStreamRef, outputStream: &outputStreamRef) 19 | 20 | guard let inputStreamRef, let outputStreamRef else { 21 | fatalError("Could not create streams") 22 | } 23 | 24 | inputStream = HybridInputStream(stream: inputStreamRef) 25 | outputStream = HybridOutputStream(stream: outputStreamRef) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/HybridInputStream.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HybridInputStream.swift 3 | // FastIO 4 | // 5 | // Created by Mike Grabowski on 06/11/2024. 6 | // 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | class HybridInputStream : HybridInputStreamSpec { 12 | let stream : InputStream 13 | 14 | init(stream: InputStream) { 15 | self.stream = stream 16 | } 17 | 18 | func open() throws -> Void { 19 | stream.open() 20 | } 21 | 22 | func read() throws -> Promise { 23 | let promise = Promise() 24 | 25 | Task { 26 | let size = Int(HybridStreamFactory.BUFFER_SIZE) 27 | let data = UnsafeMutablePointer.allocate(capacity: size) 28 | 29 | let bytesRead = stream.read(data, maxLength: size) 30 | 31 | let deleteFunc = { 32 | data.deallocate() 33 | } 34 | 35 | if (bytesRead >= 0) { 36 | promise.resolve(withResult: ArrayBufferHolder.wrap(dataWithoutCopy: data, size: bytesRead, onDelete: deleteFunc)) 37 | } else { 38 | deleteFunc() 39 | promise.reject(withError: stream.streamError ?? RuntimeError.error(withMessage: "Unexpected error reading stream")) 40 | } 41 | } 42 | 43 | return promise 44 | } 45 | 46 | func close() { 47 | stream.close() 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/HybridNetwork.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HybridNetwork.swift 3 | // FastIO 4 | // 5 | // Created by Mike Grabowski on 06/11/2024. 6 | // 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | class HybridNetwork : HybridNetworkSpec { 12 | func request(opts: RequestOptions) throws -> Promise { 13 | guard let requestUrl = URL(string: opts.url) else { 14 | return Promise.rejected(withError: NSError(domain: "Invalid URL: \(opts.url)", code: -1)) 15 | } 16 | 17 | var request = URLRequest(url: requestUrl) 18 | request.httpMethod = opts.method.stringValue 19 | 20 | if let inputStream = opts.body as? HybridInputStream { 21 | request.httpBodyStream = inputStream.stream 22 | } 23 | 24 | let promise = Promise() 25 | 26 | Task { 27 | do { 28 | let (_, response) = try await URLSession.shared.data(for: request) 29 | 30 | let statusCode = (response as! HTTPURLResponse).statusCode 31 | if (200...299).contains(statusCode) { 32 | promise.resolve(withResult: ()) 33 | } else { 34 | promise.reject(withError: NSError( 35 | domain: "HTTP Error", 36 | code: statusCode 37 | )) 38 | } 39 | 40 | } catch { 41 | promise.reject(withError: error) 42 | } 43 | } 44 | 45 | return promise 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/HybridOutputStream.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HybridOutputStream.swift 3 | // FastIO 4 | // 5 | // Created by Mike Grabowski on 07/11/2024. 6 | // 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | class HybridOutputStream : HybridOutputStreamSpec { 12 | let stream : OutputStream 13 | 14 | init(stream: OutputStream) { 15 | self.stream = stream 16 | } 17 | 18 | func open() throws -> Void { 19 | stream.open() 20 | } 21 | 22 | func write(buffer: ArrayBufferHolder) throws -> Promise { 23 | let promise = Promise() 24 | 25 | let data = buffer.data 26 | let length = buffer.size 27 | 28 | Task { 29 | let bytesWritten = stream.write(data, maxLength: length) 30 | if (bytesWritten == length) { 31 | promise.resolve(withResult: ()) 32 | } else { 33 | promise.reject(withError: stream.streamError ?? RuntimeError.error(withMessage: "Unexpected error writing to stream")) 34 | } 35 | } 36 | 37 | return promise 38 | } 39 | 40 | func close() { 41 | stream.close() 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/HybridStreamFactory.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HybridStreamFactory.swift 3 | // FastIO 4 | // 5 | // Created by Mike Grabowski on 12/11/2024. 6 | // 7 | 8 | import Foundation 9 | import FastIOPrivate 10 | 11 | class HybridStreamFactory : HybridStreamFactorySpec { 12 | static let BUFFER_SIZE = FASTIO_BUFFER_SIZE 13 | 14 | var bufferSize: Double { 15 | get { 16 | Double(HybridStreamFactory.BUFFER_SIZE) 17 | } 18 | } 19 | 20 | func createInputStream(path: String) -> any HybridInputStreamSpec { 21 | guard let stream = InputStream(fileAtPath: path) else { 22 | fatalError("Failed to create stream from \(path)") 23 | } 24 | return HybridInputStream(stream: stream) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/HybridWebSocketManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HybridStyleSheet.swift 3 | // ReactNativeFastWS 4 | // 5 | // Created by Mike Grabowski on 13/09/2024. 6 | // 7 | 8 | import NitroModules 9 | 10 | class HybridWebSocketManager : HybridWebSocketManagerSpec { 11 | func create(url: String, protocols: [String]) throws -> any HybridWebSocketSpec { 12 | return HybridWebSocket(url: url, protocols: protocols) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/WebSocketDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WebSocketDelegate.swift 3 | // ReactNativeFastWS 4 | // 5 | // Created by Mike Grabowski on 15/09/2024. 6 | // 7 | 8 | import Foundation 9 | 10 | class WebSocketDelegate: NSObject, URLSessionWebSocketDelegate { 11 | var onOpen: ((String?) -> Void)? 12 | var onClose: ((URLSessionWebSocketTask.CloseCode, Data?) -> Void)? 13 | 14 | func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol selectedProtocol: String?) { 15 | onOpen?(selectedProtocol) 16 | } 17 | 18 | func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) { 19 | onClose?(closeCode, reason) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/ios/WebSocketStream.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SocketStream.swift 3 | // ReactNativeFastWS 4 | // 5 | // Created by Mike Grabowski on 15/09/2024. 6 | // 7 | 8 | import Foundation 9 | 10 | typealias AsyncStream = AsyncThrowingStream 11 | 12 | class WebSocketStream: AsyncSequence { 13 | typealias AsyncIterator = AsyncStream.Iterator 14 | typealias Element = URLSessionWebSocketTask.Message 15 | 16 | private var continuation: AsyncStream.Continuation? 17 | let ws: URLSessionWebSocketTask 18 | 19 | private lazy var stream: AsyncStream = { 20 | return AsyncStream { continuation in 21 | self.continuation = continuation 22 | 23 | Task { 24 | var isAlive = true 25 | while isAlive && ws.closeCode == .invalid { 26 | do { 27 | let value = try await ws.receive() 28 | continuation.yield(value) 29 | } catch { 30 | continuation.finish(throwing: error) 31 | isAlive = false 32 | } 33 | } 34 | } 35 | } 36 | }() 37 | 38 | init(ws: URLSessionWebSocketTask) { 39 | self.ws = ws 40 | } 41 | 42 | func makeAsyncIterator() -> AsyncIterator { 43 | return stream.makeAsyncIterator() 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitro.json: -------------------------------------------------------------------------------- 1 | { 2 | "cxxNamespace": ["fastio"], 3 | "ios": { 4 | "iosModuleName": "FastIO" 5 | }, 6 | "android": { 7 | "androidNamespace": ["fastio"], 8 | "androidCxxLibName": "FastIO" 9 | }, 10 | "autolinking": { 11 | "WebSocketManager": { 12 | "swift": "HybridWebSocketManager", 13 | "kotlin": "HybridWebSocketManager" 14 | }, 15 | "FileSystem": { 16 | "swift": "HybridFileSystem", 17 | "kotlin": "HybridFileSystem" 18 | }, 19 | "Network": { 20 | "swift": "HybridNetwork", 21 | "kotlin": "HybridNetwork" 22 | }, 23 | "DuplexStream": { 24 | "swift": "HybridDuplexStream", 25 | "kotlin": "HybridDuplexStream" 26 | }, 27 | "CompressorFactory": { 28 | "cpp": "HybridCompressorFactory" 29 | }, 30 | "StreamFactory": { 31 | "swift": "HybridStreamFactory", 32 | "kotlin": "HybridStreamFactory" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/FastIO+autolinking.gradle: -------------------------------------------------------------------------------- 1 | /// 2 | /// FastIO+autolinking.gradle 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | /// This is a Gradle file that adds all files generated by Nitrogen 9 | /// to the current Gradle project. 10 | /// 11 | /// To use it, add this to your build.gradle: 12 | /// ```gradle 13 | /// apply from: '../nitrogen/generated/android/FastIO+autolinking.gradle' 14 | /// ``` 15 | 16 | logger.warn("[NitroModules] 🔥 FastIO is boosted by nitro!") 17 | 18 | android { 19 | sourceSets { 20 | main { 21 | java.srcDirs += [ 22 | // Nitrogen files 23 | "${project.projectDir}/../nitrogen/generated/android/kotlin" 24 | ] 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/FastIOOnLoad.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// FastIOOnLoad.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include 9 | #include 10 | 11 | namespace margelo::nitro::fastio { 12 | 13 | /** 14 | * Initializes the native (C++) part of FastIO, and autolinks all Hybrid Objects. 15 | * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`). 16 | * Example: 17 | * ```cpp (cpp-adapter.cpp) 18 | * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) { 19 | * return margelo::nitro::fastio::initialize(vm); 20 | * } 21 | * ``` 22 | */ 23 | int initialize(JavaVM* vm); 24 | 25 | } // namespace margelo::nitro::fastio 26 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/FastIOOnLoad.kt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JFunc_void_double_std__string.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JFunc_void_double_std__string.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace margelo::nitro::fastio { 17 | 18 | using namespace facebook; 19 | 20 | /** 21 | * C++ representation of the callback Func_void_double_std__string. 22 | * This is a Kotlin `(code: Double, reason: String) -> Unit`, backed by a `std::function<...>`. 23 | */ 24 | struct JFunc_void_double_std__string final: public jni::HybridClass { 25 | public: 26 | static jni::local_ref fromCpp(const std::function& func) { 27 | return JFunc_void_double_std__string::newObjectCxxArgs(func); 28 | } 29 | 30 | public: 31 | void call(double code, jni::alias_ref reason) { 32 | _func(code, reason->toStdString()); 33 | } 34 | 35 | public: 36 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/Func_void_double_std__string;"; 37 | static void registerNatives() { 38 | registerHybrid({makeNativeMethod("call", JFunc_void_double_std__string::call)}); 39 | } 40 | 41 | private: 42 | explicit JFunc_void_double_std__string(const std::function& func): _func(func) { } 43 | 44 | private: 45 | friend HybridBase; 46 | std::function _func; 47 | }; 48 | 49 | } // namespace margelo::nitro::fastio 50 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JFunc_void_std__shared_ptr_ArrayBuffer_.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JFunc_void_std__shared_ptr_ArrayBuffer_.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace margelo::nitro::fastio { 19 | 20 | using namespace facebook; 21 | 22 | /** 23 | * C++ representation of the callback Func_void_std__shared_ptr_ArrayBuffer_. 24 | * This is a Kotlin `(buffer: ArrayBuffer) -> Unit`, backed by a `std::function<...>`. 25 | */ 26 | struct JFunc_void_std__shared_ptr_ArrayBuffer_ final: public jni::HybridClass { 27 | public: 28 | static jni::local_ref fromCpp(const std::function& /* buffer */)>& func) { 29 | return JFunc_void_std__shared_ptr_ArrayBuffer_::newObjectCxxArgs(func); 30 | } 31 | 32 | public: 33 | void call(jni::alias_ref buffer) { 34 | _func(buffer->cthis()->getArrayBuffer()); 35 | } 36 | 37 | public: 38 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/Func_void_std__shared_ptr_ArrayBuffer_;"; 39 | static void registerNatives() { 40 | registerHybrid({makeNativeMethod("call", JFunc_void_std__shared_ptr_ArrayBuffer_::call)}); 41 | } 42 | 43 | private: 44 | explicit JFunc_void_std__shared_ptr_ArrayBuffer_(const std::function& /* buffer */)>& func): _func(func) { } 45 | 46 | private: 47 | friend HybridBase; 48 | std::function& /* buffer */)> _func; 49 | }; 50 | 51 | } // namespace margelo::nitro::fastio 52 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JFunc_void_std__string.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JFunc_void_std__string.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace margelo::nitro::fastio { 17 | 18 | using namespace facebook; 19 | 20 | /** 21 | * C++ representation of the callback Func_void_std__string. 22 | * This is a Kotlin `(message: String) -> Unit`, backed by a `std::function<...>`. 23 | */ 24 | struct JFunc_void_std__string final: public jni::HybridClass { 25 | public: 26 | static jni::local_ref fromCpp(const std::function& func) { 27 | return JFunc_void_std__string::newObjectCxxArgs(func); 28 | } 29 | 30 | public: 31 | void call(jni::alias_ref message) { 32 | _func(message->toStdString()); 33 | } 34 | 35 | public: 36 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/Func_void_std__string;"; 37 | static void registerNatives() { 38 | registerHybrid({makeNativeMethod("call", JFunc_void_std__string::call)}); 39 | } 40 | 41 | private: 42 | explicit JFunc_void_std__string(const std::function& func): _func(func) { } 43 | 44 | private: 45 | friend HybridBase; 46 | std::function _func; 47 | }; 48 | 49 | } // namespace margelo::nitro::fastio 50 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridDuplexStreamSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridDuplexStreamSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "HybridDuplexStreamSpec.hpp" 13 | 14 | 15 | 16 | 17 | namespace margelo::nitro::fastio { 18 | 19 | using namespace facebook; 20 | 21 | class JHybridDuplexStreamSpec: public jni::HybridClass, 22 | public virtual HybridDuplexStreamSpec { 23 | public: 24 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/HybridDuplexStreamSpec;"; 25 | static jni::local_ref initHybrid(jni::alias_ref jThis); 26 | static void registerNatives(); 27 | 28 | protected: 29 | // C++ constructor (called from Java via `initHybrid()`) 30 | explicit JHybridDuplexStreamSpec(jni::alias_ref jThis) : 31 | HybridObject(HybridDuplexStreamSpec::TAG), 32 | _javaPart(jni::make_global(jThis)) {} 33 | 34 | public: 35 | virtual ~JHybridDuplexStreamSpec() { 36 | // Hermes GC can destroy JS objects on a non-JNI Thread. 37 | jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); }); 38 | } 39 | 40 | public: 41 | size_t getExternalMemorySize() noexcept override; 42 | 43 | public: 44 | inline const jni::global_ref& getJavaPart() const noexcept { 45 | return _javaPart; 46 | } 47 | 48 | public: 49 | // Properties 50 | std::shared_ptr getInputStream() override; 51 | void setInputStream(const std::shared_ptr& inputStream) override; 52 | std::shared_ptr getOutputStream() override; 53 | void setOutputStream(const std::shared_ptr& outputStream) override; 54 | 55 | public: 56 | // Methods 57 | 58 | 59 | private: 60 | friend HybridBase; 61 | using HybridBase::HybridBase; 62 | jni::global_ref _javaPart; 63 | }; 64 | 65 | } // namespace margelo::nitro::fastio 66 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridFileSystemSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridFileSystemSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "HybridFileSystemSpec.hpp" 13 | 14 | 15 | 16 | 17 | namespace margelo::nitro::fastio { 18 | 19 | using namespace facebook; 20 | 21 | class JHybridFileSystemSpec: public jni::HybridClass, 22 | public virtual HybridFileSystemSpec { 23 | public: 24 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/HybridFileSystemSpec;"; 25 | static jni::local_ref initHybrid(jni::alias_ref jThis); 26 | static void registerNatives(); 27 | 28 | protected: 29 | // C++ constructor (called from Java via `initHybrid()`) 30 | explicit JHybridFileSystemSpec(jni::alias_ref jThis) : 31 | HybridObject(HybridFileSystemSpec::TAG), 32 | _javaPart(jni::make_global(jThis)) {} 33 | 34 | public: 35 | virtual ~JHybridFileSystemSpec() { 36 | // Hermes GC can destroy JS objects on a non-JNI Thread. 37 | jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); }); 38 | } 39 | 40 | public: 41 | size_t getExternalMemorySize() noexcept override; 42 | 43 | public: 44 | inline const jni::global_ref& getJavaPart() const noexcept { 45 | return _javaPart; 46 | } 47 | 48 | public: 49 | // Properties 50 | 51 | 52 | public: 53 | // Methods 54 | Metadata getMetadata(const std::string& path) override; 55 | std::string getWellKnownDirectoryPath(WellKnownDirectory directory) override; 56 | std::shared_ptr>> showOpenFilePicker(const std::optional& options) override; 57 | 58 | private: 59 | friend HybridBase; 60 | using HybridBase::HybridBase; 61 | jni::global_ref _javaPart; 62 | }; 63 | 64 | } // namespace margelo::nitro::fastio 65 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridInputStreamSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JHybridInputStreamSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "JHybridInputStreamSpec.hpp" 9 | 10 | // Forward declaration of `ArrayBuffer` to properly resolve imports. 11 | namespace NitroModules { class ArrayBuffer; } 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace margelo::nitro::fastio { 20 | 21 | jni::local_ref JHybridInputStreamSpec::initHybrid(jni::alias_ref jThis) { 22 | return makeCxxInstance(jThis); 23 | } 24 | 25 | void JHybridInputStreamSpec::registerNatives() { 26 | registerHybrid({ 27 | makeNativeMethod("initHybrid", JHybridInputStreamSpec::initHybrid), 28 | }); 29 | } 30 | 31 | size_t JHybridInputStreamSpec::getExternalMemorySize() noexcept { 32 | static const auto method = _javaPart->getClass()->getMethod("getMemorySize"); 33 | return method(_javaPart); 34 | } 35 | 36 | // Properties 37 | 38 | 39 | // Methods 40 | std::shared_ptr>> JHybridInputStreamSpec::read() { 41 | static const auto method = _javaPart->getClass()->getMethod()>("read"); 42 | auto __result = method(_javaPart); 43 | return [&]() { 44 | auto __promise = Promise>::create(); 45 | __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { 46 | auto __result = jni::static_ref_cast(__boxedResult); 47 | __promise->resolve(__result->cthis()->getArrayBuffer()); 48 | }); 49 | __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { 50 | jni::JniException __jniError(__throwable); 51 | __promise->reject(std::make_exception_ptr(__jniError)); 52 | }); 53 | return __promise; 54 | }(); 55 | } 56 | void JHybridInputStreamSpec::open() { 57 | static const auto method = _javaPart->getClass()->getMethod("open"); 58 | method(_javaPart); 59 | } 60 | void JHybridInputStreamSpec::close() { 61 | static const auto method = _javaPart->getClass()->getMethod("close"); 62 | method(_javaPart); 63 | } 64 | 65 | } // namespace margelo::nitro::fastio 66 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridInputStreamSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridInputStreamSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "HybridInputStreamSpec.hpp" 13 | 14 | 15 | 16 | 17 | namespace margelo::nitro::fastio { 18 | 19 | using namespace facebook; 20 | 21 | class JHybridInputStreamSpec: public jni::HybridClass, 22 | public virtual HybridInputStreamSpec { 23 | public: 24 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/HybridInputStreamSpec;"; 25 | static jni::local_ref initHybrid(jni::alias_ref jThis); 26 | static void registerNatives(); 27 | 28 | protected: 29 | // C++ constructor (called from Java via `initHybrid()`) 30 | explicit JHybridInputStreamSpec(jni::alias_ref jThis) : 31 | HybridObject(HybridInputStreamSpec::TAG), 32 | _javaPart(jni::make_global(jThis)) {} 33 | 34 | public: 35 | virtual ~JHybridInputStreamSpec() { 36 | // Hermes GC can destroy JS objects on a non-JNI Thread. 37 | jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); }); 38 | } 39 | 40 | public: 41 | size_t getExternalMemorySize() noexcept override; 42 | 43 | public: 44 | inline const jni::global_ref& getJavaPart() const noexcept { 45 | return _javaPart; 46 | } 47 | 48 | public: 49 | // Properties 50 | 51 | 52 | public: 53 | // Methods 54 | std::shared_ptr>> read() override; 55 | void open() override; 56 | void close() override; 57 | 58 | private: 59 | friend HybridBase; 60 | using HybridBase::HybridBase; 61 | jni::global_ref _javaPart; 62 | }; 63 | 64 | } // namespace margelo::nitro::fastio 65 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridNetworkSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JHybridNetworkSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "JHybridNetworkSpec.hpp" 9 | 10 | // Forward declaration of `RequestOptions` to properly resolve imports. 11 | namespace margelo::nitro::fastio { struct RequestOptions; } 12 | // Forward declaration of `RequestMethod` to properly resolve imports. 13 | namespace margelo::nitro::fastio { enum class RequestMethod; } 14 | // Forward declaration of `HybridInputStreamSpec` to properly resolve imports. 15 | namespace margelo::nitro::fastio { class HybridInputStreamSpec; } 16 | 17 | #include 18 | #include 19 | #include "RequestOptions.hpp" 20 | #include "JRequestOptions.hpp" 21 | #include 22 | #include "RequestMethod.hpp" 23 | #include "JRequestMethod.hpp" 24 | #include 25 | #include 26 | #include "HybridInputStreamSpec.hpp" 27 | #include "JHybridInputStreamSpec.hpp" 28 | #include 29 | 30 | namespace margelo::nitro::fastio { 31 | 32 | jni::local_ref JHybridNetworkSpec::initHybrid(jni::alias_ref jThis) { 33 | return makeCxxInstance(jThis); 34 | } 35 | 36 | void JHybridNetworkSpec::registerNatives() { 37 | registerHybrid({ 38 | makeNativeMethod("initHybrid", JHybridNetworkSpec::initHybrid), 39 | }); 40 | } 41 | 42 | size_t JHybridNetworkSpec::getExternalMemorySize() noexcept { 43 | static const auto method = _javaPart->getClass()->getMethod("getMemorySize"); 44 | return method(_javaPart); 45 | } 46 | 47 | // Properties 48 | 49 | 50 | // Methods 51 | std::shared_ptr> JHybridNetworkSpec::request(const RequestOptions& opts) { 52 | static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* opts */)>("request"); 53 | auto __result = method(_javaPart, JRequestOptions::fromCpp(opts)); 54 | return [&]() { 55 | auto __promise = Promise::create(); 56 | __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { 57 | __promise->resolve(); 58 | }); 59 | __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { 60 | jni::JniException __jniError(__throwable); 61 | __promise->reject(std::make_exception_ptr(__jniError)); 62 | }); 63 | return __promise; 64 | }(); 65 | } 66 | 67 | } // namespace margelo::nitro::fastio 68 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridNetworkSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridNetworkSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "HybridNetworkSpec.hpp" 13 | 14 | 15 | 16 | 17 | namespace margelo::nitro::fastio { 18 | 19 | using namespace facebook; 20 | 21 | class JHybridNetworkSpec: public jni::HybridClass, 22 | public virtual HybridNetworkSpec { 23 | public: 24 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/HybridNetworkSpec;"; 25 | static jni::local_ref initHybrid(jni::alias_ref jThis); 26 | static void registerNatives(); 27 | 28 | protected: 29 | // C++ constructor (called from Java via `initHybrid()`) 30 | explicit JHybridNetworkSpec(jni::alias_ref jThis) : 31 | HybridObject(HybridNetworkSpec::TAG), 32 | _javaPart(jni::make_global(jThis)) {} 33 | 34 | public: 35 | virtual ~JHybridNetworkSpec() { 36 | // Hermes GC can destroy JS objects on a non-JNI Thread. 37 | jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); }); 38 | } 39 | 40 | public: 41 | size_t getExternalMemorySize() noexcept override; 42 | 43 | public: 44 | inline const jni::global_ref& getJavaPart() const noexcept { 45 | return _javaPart; 46 | } 47 | 48 | public: 49 | // Properties 50 | 51 | 52 | public: 53 | // Methods 54 | std::shared_ptr> request(const RequestOptions& opts) override; 55 | 56 | private: 57 | friend HybridBase; 58 | using HybridBase::HybridBase; 59 | jni::global_ref _javaPart; 60 | }; 61 | 62 | } // namespace margelo::nitro::fastio 63 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridOutputStreamSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JHybridOutputStreamSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "JHybridOutputStreamSpec.hpp" 9 | 10 | // Forward declaration of `ArrayBuffer` to properly resolve imports. 11 | namespace NitroModules { class ArrayBuffer; } 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace margelo::nitro::fastio { 20 | 21 | jni::local_ref JHybridOutputStreamSpec::initHybrid(jni::alias_ref jThis) { 22 | return makeCxxInstance(jThis); 23 | } 24 | 25 | void JHybridOutputStreamSpec::registerNatives() { 26 | registerHybrid({ 27 | makeNativeMethod("initHybrid", JHybridOutputStreamSpec::initHybrid), 28 | }); 29 | } 30 | 31 | size_t JHybridOutputStreamSpec::getExternalMemorySize() noexcept { 32 | static const auto method = _javaPart->getClass()->getMethod("getMemorySize"); 33 | return method(_javaPart); 34 | } 35 | 36 | // Properties 37 | 38 | 39 | // Methods 40 | std::shared_ptr> JHybridOutputStreamSpec::write(const std::shared_ptr& buffer) { 41 | static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* buffer */)>("write"); 42 | auto __result = method(_javaPart, JArrayBuffer::wrap(buffer)); 43 | return [&]() { 44 | auto __promise = Promise::create(); 45 | __result->cthis()->addOnResolvedListener([=](const jni::alias_ref& __boxedResult) { 46 | __promise->resolve(); 47 | }); 48 | __result->cthis()->addOnRejectedListener([=](const jni::alias_ref& __throwable) { 49 | jni::JniException __jniError(__throwable); 50 | __promise->reject(std::make_exception_ptr(__jniError)); 51 | }); 52 | return __promise; 53 | }(); 54 | } 55 | void JHybridOutputStreamSpec::open() { 56 | static const auto method = _javaPart->getClass()->getMethod("open"); 57 | method(_javaPart); 58 | } 59 | void JHybridOutputStreamSpec::close() { 60 | static const auto method = _javaPart->getClass()->getMethod("close"); 61 | method(_javaPart); 62 | } 63 | 64 | } // namespace margelo::nitro::fastio 65 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridOutputStreamSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridOutputStreamSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "HybridOutputStreamSpec.hpp" 13 | 14 | 15 | 16 | 17 | namespace margelo::nitro::fastio { 18 | 19 | using namespace facebook; 20 | 21 | class JHybridOutputStreamSpec: public jni::HybridClass, 22 | public virtual HybridOutputStreamSpec { 23 | public: 24 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/HybridOutputStreamSpec;"; 25 | static jni::local_ref initHybrid(jni::alias_ref jThis); 26 | static void registerNatives(); 27 | 28 | protected: 29 | // C++ constructor (called from Java via `initHybrid()`) 30 | explicit JHybridOutputStreamSpec(jni::alias_ref jThis) : 31 | HybridObject(HybridOutputStreamSpec::TAG), 32 | _javaPart(jni::make_global(jThis)) {} 33 | 34 | public: 35 | virtual ~JHybridOutputStreamSpec() { 36 | // Hermes GC can destroy JS objects on a non-JNI Thread. 37 | jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); }); 38 | } 39 | 40 | public: 41 | size_t getExternalMemorySize() noexcept override; 42 | 43 | public: 44 | inline const jni::global_ref& getJavaPart() const noexcept { 45 | return _javaPart; 46 | } 47 | 48 | public: 49 | // Properties 50 | 51 | 52 | public: 53 | // Methods 54 | std::shared_ptr> write(const std::shared_ptr& buffer) override; 55 | void open() override; 56 | void close() override; 57 | 58 | private: 59 | friend HybridBase; 60 | using HybridBase::HybridBase; 61 | jni::global_ref _javaPart; 62 | }; 63 | 64 | } // namespace margelo::nitro::fastio 65 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridStreamFactorySpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JHybridStreamFactorySpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "JHybridStreamFactorySpec.hpp" 9 | 10 | // Forward declaration of `HybridInputStreamSpec` to properly resolve imports. 11 | namespace margelo::nitro::fastio { class HybridInputStreamSpec; } 12 | 13 | #include 14 | #include "HybridInputStreamSpec.hpp" 15 | #include "JHybridInputStreamSpec.hpp" 16 | #include 17 | #include 18 | 19 | namespace margelo::nitro::fastio { 20 | 21 | jni::local_ref JHybridStreamFactorySpec::initHybrid(jni::alias_ref jThis) { 22 | return makeCxxInstance(jThis); 23 | } 24 | 25 | void JHybridStreamFactorySpec::registerNatives() { 26 | registerHybrid({ 27 | makeNativeMethod("initHybrid", JHybridStreamFactorySpec::initHybrid), 28 | }); 29 | } 30 | 31 | size_t JHybridStreamFactorySpec::getExternalMemorySize() noexcept { 32 | static const auto method = _javaPart->getClass()->getMethod("getMemorySize"); 33 | return method(_javaPart); 34 | } 35 | 36 | // Properties 37 | double JHybridStreamFactorySpec::getBufferSize() { 38 | static const auto method = _javaPart->getClass()->getMethod("getBufferSize"); 39 | auto __result = method(_javaPart); 40 | return __result; 41 | } 42 | 43 | // Methods 44 | std::shared_ptr JHybridStreamFactorySpec::createInputStream(const std::string& path) { 45 | static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* path */)>("createInputStream"); 46 | auto __result = method(_javaPart, jni::make_jstring(path)); 47 | return JNISharedPtr::make_shared_from_jni(jni::make_global(__result)); 48 | } 49 | 50 | } // namespace margelo::nitro::fastio 51 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridStreamFactorySpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridStreamFactorySpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "HybridStreamFactorySpec.hpp" 13 | 14 | 15 | 16 | 17 | namespace margelo::nitro::fastio { 18 | 19 | using namespace facebook; 20 | 21 | class JHybridStreamFactorySpec: public jni::HybridClass, 22 | public virtual HybridStreamFactorySpec { 23 | public: 24 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/HybridStreamFactorySpec;"; 25 | static jni::local_ref initHybrid(jni::alias_ref jThis); 26 | static void registerNatives(); 27 | 28 | protected: 29 | // C++ constructor (called from Java via `initHybrid()`) 30 | explicit JHybridStreamFactorySpec(jni::alias_ref jThis) : 31 | HybridObject(HybridStreamFactorySpec::TAG), 32 | _javaPart(jni::make_global(jThis)) {} 33 | 34 | public: 35 | virtual ~JHybridStreamFactorySpec() { 36 | // Hermes GC can destroy JS objects on a non-JNI Thread. 37 | jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); }); 38 | } 39 | 40 | public: 41 | size_t getExternalMemorySize() noexcept override; 42 | 43 | public: 44 | inline const jni::global_ref& getJavaPart() const noexcept { 45 | return _javaPart; 46 | } 47 | 48 | public: 49 | // Properties 50 | double getBufferSize() override; 51 | 52 | public: 53 | // Methods 54 | std::shared_ptr createInputStream(const std::string& path) override; 55 | 56 | private: 57 | friend HybridBase; 58 | using HybridBase::HybridBase; 59 | jni::global_ref _javaPart; 60 | }; 61 | 62 | } // namespace margelo::nitro::fastio 63 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridWebSocketManagerSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JHybridWebSocketManagerSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "JHybridWebSocketManagerSpec.hpp" 9 | 10 | // Forward declaration of `HybridWebSocketSpec` to properly resolve imports. 11 | namespace margelo::nitro::fastio { class HybridWebSocketSpec; } 12 | 13 | #include 14 | #include "HybridWebSocketSpec.hpp" 15 | #include "JHybridWebSocketSpec.hpp" 16 | #include 17 | #include 18 | #include 19 | 20 | namespace margelo::nitro::fastio { 21 | 22 | jni::local_ref JHybridWebSocketManagerSpec::initHybrid(jni::alias_ref jThis) { 23 | return makeCxxInstance(jThis); 24 | } 25 | 26 | void JHybridWebSocketManagerSpec::registerNatives() { 27 | registerHybrid({ 28 | makeNativeMethod("initHybrid", JHybridWebSocketManagerSpec::initHybrid), 29 | }); 30 | } 31 | 32 | size_t JHybridWebSocketManagerSpec::getExternalMemorySize() noexcept { 33 | static const auto method = _javaPart->getClass()->getMethod("getMemorySize"); 34 | return method(_javaPart); 35 | } 36 | 37 | // Properties 38 | 39 | 40 | // Methods 41 | std::shared_ptr JHybridWebSocketManagerSpec::create(const std::string& url, const std::vector& protocols) { 42 | static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* url */, jni::alias_ref> /* protocols */)>("create"); 43 | auto __result = method(_javaPart, jni::make_jstring(url), [&]() { 44 | size_t __size = protocols.size(); 45 | jni::local_ref> __array = jni::JArrayClass::newArray(__size); 46 | for (size_t __i = 0; __i < __size; __i++) { 47 | const auto& __element = protocols[__i]; 48 | __array->setElement(__i, *jni::make_jstring(__element)); 49 | } 50 | return __array; 51 | }()); 52 | return JNISharedPtr::make_shared_from_jni(jni::make_global(__result)); 53 | } 54 | 55 | } // namespace margelo::nitro::fastio 56 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridWebSocketManagerSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridWebSocketManagerSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include "HybridWebSocketManagerSpec.hpp" 13 | 14 | 15 | 16 | 17 | namespace margelo::nitro::fastio { 18 | 19 | using namespace facebook; 20 | 21 | class JHybridWebSocketManagerSpec: public jni::HybridClass, 22 | public virtual HybridWebSocketManagerSpec { 23 | public: 24 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/HybridWebSocketManagerSpec;"; 25 | static jni::local_ref initHybrid(jni::alias_ref jThis); 26 | static void registerNatives(); 27 | 28 | protected: 29 | // C++ constructor (called from Java via `initHybrid()`) 30 | explicit JHybridWebSocketManagerSpec(jni::alias_ref jThis) : 31 | HybridObject(HybridWebSocketManagerSpec::TAG), 32 | _javaPart(jni::make_global(jThis)) {} 33 | 34 | public: 35 | virtual ~JHybridWebSocketManagerSpec() { 36 | // Hermes GC can destroy JS objects on a non-JNI Thread. 37 | jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); }); 38 | } 39 | 40 | public: 41 | size_t getExternalMemorySize() noexcept override; 42 | 43 | public: 44 | inline const jni::global_ref& getJavaPart() const noexcept { 45 | return _javaPart; 46 | } 47 | 48 | public: 49 | // Properties 50 | 51 | 52 | public: 53 | // Methods 54 | std::shared_ptr create(const std::string& url, const std::vector& protocols) override; 55 | 56 | private: 57 | friend HybridBase; 58 | using HybridBase::HybridBase; 59 | jni::global_ref _javaPart; 60 | }; 61 | 62 | } // namespace margelo::nitro::fastio 63 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JRequestMethod.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JRequestMethod.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "RequestMethod.hpp" 12 | 13 | namespace margelo::nitro::fastio { 14 | 15 | using namespace facebook; 16 | 17 | /** 18 | * The C++ JNI bridge between the C++ enum "RequestMethod" and the the Kotlin enum "RequestMethod". 19 | */ 20 | struct JRequestMethod final: public jni::JavaClass { 21 | public: 22 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/RequestMethod;"; 23 | 24 | public: 25 | /** 26 | * Convert this Java/Kotlin-based enum to the C++ enum RequestMethod. 27 | */ 28 | [[maybe_unused]] 29 | RequestMethod toCpp() const { 30 | static const auto clazz = javaClassStatic(); 31 | static const auto fieldOrdinal = clazz->getField("_ordinal"); 32 | int ordinal = this->getFieldValue(fieldOrdinal); 33 | return static_cast(ordinal); 34 | } 35 | 36 | public: 37 | /** 38 | * Create a Java/Kotlin-based enum with the given C++ enum's value. 39 | */ 40 | [[maybe_unused]] 41 | static jni::alias_ref fromCpp(RequestMethod value) { 42 | static const auto clazz = javaClassStatic(); 43 | static const auto fieldPOST = clazz->getStaticField("POST"); 44 | static const auto fieldGET = clazz->getStaticField("GET"); 45 | 46 | switch (value) { 47 | case RequestMethod::POST: 48 | return clazz->getStaticFieldValue(fieldPOST); 49 | case RequestMethod::GET: 50 | return clazz->getStaticFieldValue(fieldGET); 51 | default: 52 | std::string stringValue = std::to_string(static_cast(value)); 53 | throw std::invalid_argument("Invalid enum value (" + stringValue + "!"); 54 | } 55 | } 56 | }; 57 | 58 | } // namespace margelo::nitro::fastio 59 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/c++/JRequestOptions.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// JRequestOptions.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "RequestOptions.hpp" 12 | 13 | #include "HybridInputStreamSpec.hpp" 14 | #include "JHybridInputStreamSpec.hpp" 15 | #include "JRequestMethod.hpp" 16 | #include "RequestMethod.hpp" 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace margelo::nitro::fastio { 23 | 24 | using namespace facebook; 25 | 26 | /** 27 | * The C++ JNI bridge between the C++ struct "RequestOptions" and the the Kotlin data class "RequestOptions". 28 | */ 29 | struct JRequestOptions final: public jni::JavaClass { 30 | public: 31 | static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/fastio/RequestOptions;"; 32 | 33 | public: 34 | /** 35 | * Convert this Java/Kotlin-based struct to the C++ struct RequestOptions by copying all values to C++. 36 | */ 37 | [[maybe_unused]] 38 | RequestOptions toCpp() const { 39 | static const auto clazz = javaClassStatic(); 40 | static const auto fieldUrl = clazz->getField("url"); 41 | jni::local_ref url = this->getFieldValue(fieldUrl); 42 | static const auto fieldMethod = clazz->getField("method"); 43 | jni::local_ref method = this->getFieldValue(fieldMethod); 44 | static const auto fieldBody = clazz->getField("body"); 45 | jni::local_ref body = this->getFieldValue(fieldBody); 46 | return RequestOptions( 47 | url->toStdString(), 48 | method->toCpp(), 49 | body != nullptr ? std::make_optional(JNISharedPtr::make_shared_from_jni(jni::make_global(body))) : std::nullopt 50 | ); 51 | } 52 | 53 | public: 54 | /** 55 | * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java. 56 | */ 57 | [[maybe_unused]] 58 | static jni::local_ref fromCpp(const RequestOptions& value) { 59 | return newInstance( 60 | jni::make_jstring(value.url), 61 | JRequestMethod::fromCpp(value.method), 62 | value.body.has_value() ? std::dynamic_pointer_cast(value.body.value())->getJavaPart() : nullptr 63 | ); 64 | } 65 | }; 66 | 67 | } // namespace margelo::nitro::fastio 68 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/Func_void_double_std__string.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// Func_void_double_std__string.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import androidx.annotation.Keep 11 | import com.facebook.jni.HybridData 12 | import com.facebook.proguard.annotations.DoNotStrip 13 | import com.margelo.nitro.core.* 14 | import dalvik.annotation.optimization.FastNative 15 | 16 | /** 17 | * Represents the JavaScript callback `(code: number, reason: string) => void`. 18 | * This is implemented in C++, via a `std::function<...>`. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") 23 | class Func_void_double_std__string { 24 | @DoNotStrip 25 | @Keep 26 | private val mHybridData: HybridData 27 | 28 | @DoNotStrip 29 | @Keep 30 | private constructor(hybridData: HybridData) { 31 | mHybridData = hybridData 32 | } 33 | 34 | /** 35 | * Converts this function to a Kotlin Lambda. 36 | * This exists purely as syntactic sugar, and has minimal runtime overhead. 37 | */ 38 | fun toLambda(): (code: Double, reason: String) -> Unit = this::call 39 | 40 | /** 41 | * Call the given JS callback. 42 | * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. 43 | */ 44 | @FastNative 45 | external fun call(code: Double, reason: String): Unit 46 | } 47 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/Func_void_std__shared_ptr_ArrayBuffer_.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// Func_void_std__shared_ptr_ArrayBuffer_.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import androidx.annotation.Keep 11 | import com.facebook.jni.HybridData 12 | import com.facebook.proguard.annotations.DoNotStrip 13 | import com.margelo.nitro.core.* 14 | import dalvik.annotation.optimization.FastNative 15 | 16 | /** 17 | * Represents the JavaScript callback `(buffer: array-buffer) => void`. 18 | * This is implemented in C++, via a `std::function<...>`. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") 23 | class Func_void_std__shared_ptr_ArrayBuffer_ { 24 | @DoNotStrip 25 | @Keep 26 | private val mHybridData: HybridData 27 | 28 | @DoNotStrip 29 | @Keep 30 | private constructor(hybridData: HybridData) { 31 | mHybridData = hybridData 32 | } 33 | 34 | /** 35 | * Converts this function to a Kotlin Lambda. 36 | * This exists purely as syntactic sugar, and has minimal runtime overhead. 37 | */ 38 | fun toLambda(): (buffer: ArrayBuffer) -> Unit = this::call 39 | 40 | /** 41 | * Call the given JS callback. 42 | * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. 43 | */ 44 | @FastNative 45 | external fun call(buffer: ArrayBuffer): Unit 46 | } 47 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/Func_void_std__string.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// Func_void_std__string.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import androidx.annotation.Keep 11 | import com.facebook.jni.HybridData 12 | import com.facebook.proguard.annotations.DoNotStrip 13 | import com.margelo.nitro.core.* 14 | import dalvik.annotation.optimization.FastNative 15 | 16 | /** 17 | * Represents the JavaScript callback `(message: string) => void`. 18 | * This is implemented in C++, via a `std::function<...>`. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused") 23 | class Func_void_std__string { 24 | @DoNotStrip 25 | @Keep 26 | private val mHybridData: HybridData 27 | 28 | @DoNotStrip 29 | @Keep 30 | private constructor(hybridData: HybridData) { 31 | mHybridData = hybridData 32 | } 33 | 34 | /** 35 | * Converts this function to a Kotlin Lambda. 36 | * This exists purely as syntactic sugar, and has minimal runtime overhead. 37 | */ 38 | fun toLambda(): (message: String) -> Unit = this::call 39 | 40 | /** 41 | * Call the given JS callback. 42 | * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted. 43 | */ 44 | @FastNative 45 | external fun call(message: String): Unit 46 | } 47 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/HybridDuplexStreamSpec.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridDuplexStreamSpec.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import android.util.Log 11 | import androidx.annotation.Keep 12 | import com.facebook.jni.HybridData 13 | import com.facebook.proguard.annotations.DoNotStrip 14 | import com.margelo.nitro.core.* 15 | 16 | /** 17 | * A Kotlin class representing the DuplexStream HybridObject. 18 | * Implement this abstract class to create Kotlin-based instances of DuplexStream. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") 23 | abstract class HybridDuplexStreamSpec: HybridObject() { 24 | @DoNotStrip 25 | private var mHybridData: HybridData = initHybrid() 26 | 27 | init { 28 | // Pass this `HybridData` through to it's base class, 29 | // to represent inheritance to JHybridObject on C++ side 30 | super.updateNative(mHybridData) 31 | } 32 | 33 | /** 34 | * Call from a child class to initialize HybridData with a child. 35 | */ 36 | override fun updateNative(hybridData: HybridData) { 37 | mHybridData = hybridData 38 | } 39 | 40 | // Properties 41 | @get:DoNotStrip 42 | @get:Keep 43 | @set:DoNotStrip 44 | @set:Keep 45 | abstract var inputStream: HybridInputStreamSpec 46 | 47 | @get:DoNotStrip 48 | @get:Keep 49 | @set:DoNotStrip 50 | @set:Keep 51 | abstract var outputStream: HybridOutputStreamSpec 52 | 53 | // Methods 54 | 55 | 56 | private external fun initHybrid(): HybridData 57 | 58 | companion object { 59 | private const val TAG = "HybridDuplexStreamSpec" 60 | init { 61 | try { 62 | Log.i(TAG, "Loading FastIO C++ library...") 63 | System.loadLibrary("FastIO") 64 | Log.i(TAG, "Successfully loaded FastIO C++ library!") 65 | } catch (e: Error) { 66 | Log.e(TAG, "Failed to load FastIO C++ library! Is it properly installed and linked? " + 67 | "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e) 68 | throw e 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/HybridFileSystemSpec.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridFileSystemSpec.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import android.util.Log 11 | import androidx.annotation.Keep 12 | import com.facebook.jni.HybridData 13 | import com.facebook.proguard.annotations.DoNotStrip 14 | import com.margelo.nitro.core.* 15 | 16 | /** 17 | * A Kotlin class representing the FileSystem HybridObject. 18 | * Implement this abstract class to create Kotlin-based instances of FileSystem. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") 23 | abstract class HybridFileSystemSpec: HybridObject() { 24 | @DoNotStrip 25 | private var mHybridData: HybridData = initHybrid() 26 | 27 | init { 28 | // Pass this `HybridData` through to it's base class, 29 | // to represent inheritance to JHybridObject on C++ side 30 | super.updateNative(mHybridData) 31 | } 32 | 33 | /** 34 | * Call from a child class to initialize HybridData with a child. 35 | */ 36 | override fun updateNative(hybridData: HybridData) { 37 | mHybridData = hybridData 38 | } 39 | 40 | // Properties 41 | 42 | 43 | // Methods 44 | @DoNotStrip 45 | @Keep 46 | abstract fun getMetadata(path: String): Metadata 47 | 48 | @DoNotStrip 49 | @Keep 50 | abstract fun getWellKnownDirectoryPath(directory: WellKnownDirectory): String 51 | 52 | @DoNotStrip 53 | @Keep 54 | abstract fun showOpenFilePicker(options: NativeFilePickerOptions?): Promise> 55 | 56 | private external fun initHybrid(): HybridData 57 | 58 | companion object { 59 | private const val TAG = "HybridFileSystemSpec" 60 | init { 61 | try { 62 | Log.i(TAG, "Loading FastIO C++ library...") 63 | System.loadLibrary("FastIO") 64 | Log.i(TAG, "Successfully loaded FastIO C++ library!") 65 | } catch (e: Error) { 66 | Log.e(TAG, "Failed to load FastIO C++ library! Is it properly installed and linked? " + 67 | "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e) 68 | throw e 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/HybridInputStreamSpec.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridInputStreamSpec.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import android.util.Log 11 | import androidx.annotation.Keep 12 | import com.facebook.jni.HybridData 13 | import com.facebook.proguard.annotations.DoNotStrip 14 | import com.margelo.nitro.core.* 15 | 16 | /** 17 | * A Kotlin class representing the InputStream HybridObject. 18 | * Implement this abstract class to create Kotlin-based instances of InputStream. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") 23 | abstract class HybridInputStreamSpec: HybridObject() { 24 | @DoNotStrip 25 | private var mHybridData: HybridData = initHybrid() 26 | 27 | init { 28 | // Pass this `HybridData` through to it's base class, 29 | // to represent inheritance to JHybridObject on C++ side 30 | super.updateNative(mHybridData) 31 | } 32 | 33 | /** 34 | * Call from a child class to initialize HybridData with a child. 35 | */ 36 | override fun updateNative(hybridData: HybridData) { 37 | mHybridData = hybridData 38 | } 39 | 40 | // Properties 41 | 42 | 43 | // Methods 44 | @DoNotStrip 45 | @Keep 46 | abstract fun read(): Promise 47 | 48 | @DoNotStrip 49 | @Keep 50 | abstract fun open(): Unit 51 | 52 | @DoNotStrip 53 | @Keep 54 | abstract fun close(): Unit 55 | 56 | private external fun initHybrid(): HybridData 57 | 58 | companion object { 59 | private const val TAG = "HybridInputStreamSpec" 60 | init { 61 | try { 62 | Log.i(TAG, "Loading FastIO C++ library...") 63 | System.loadLibrary("FastIO") 64 | Log.i(TAG, "Successfully loaded FastIO C++ library!") 65 | } catch (e: Error) { 66 | Log.e(TAG, "Failed to load FastIO C++ library! Is it properly installed and linked? " + 67 | "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e) 68 | throw e 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/HybridNetworkSpec.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridNetworkSpec.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import android.util.Log 11 | import androidx.annotation.Keep 12 | import com.facebook.jni.HybridData 13 | import com.facebook.proguard.annotations.DoNotStrip 14 | import com.margelo.nitro.core.* 15 | 16 | /** 17 | * A Kotlin class representing the Network HybridObject. 18 | * Implement this abstract class to create Kotlin-based instances of Network. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") 23 | abstract class HybridNetworkSpec: HybridObject() { 24 | @DoNotStrip 25 | private var mHybridData: HybridData = initHybrid() 26 | 27 | init { 28 | // Pass this `HybridData` through to it's base class, 29 | // to represent inheritance to JHybridObject on C++ side 30 | super.updateNative(mHybridData) 31 | } 32 | 33 | /** 34 | * Call from a child class to initialize HybridData with a child. 35 | */ 36 | override fun updateNative(hybridData: HybridData) { 37 | mHybridData = hybridData 38 | } 39 | 40 | // Properties 41 | 42 | 43 | // Methods 44 | @DoNotStrip 45 | @Keep 46 | abstract fun request(opts: RequestOptions): Promise 47 | 48 | private external fun initHybrid(): HybridData 49 | 50 | companion object { 51 | private const val TAG = "HybridNetworkSpec" 52 | init { 53 | try { 54 | Log.i(TAG, "Loading FastIO C++ library...") 55 | System.loadLibrary("FastIO") 56 | Log.i(TAG, "Successfully loaded FastIO C++ library!") 57 | } catch (e: Error) { 58 | Log.e(TAG, "Failed to load FastIO C++ library! Is it properly installed and linked? " + 59 | "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e) 60 | throw e 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/HybridOutputStreamSpec.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridOutputStreamSpec.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import android.util.Log 11 | import androidx.annotation.Keep 12 | import com.facebook.jni.HybridData 13 | import com.facebook.proguard.annotations.DoNotStrip 14 | import com.margelo.nitro.core.* 15 | 16 | /** 17 | * A Kotlin class representing the OutputStream HybridObject. 18 | * Implement this abstract class to create Kotlin-based instances of OutputStream. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") 23 | abstract class HybridOutputStreamSpec: HybridObject() { 24 | @DoNotStrip 25 | private var mHybridData: HybridData = initHybrid() 26 | 27 | init { 28 | // Pass this `HybridData` through to it's base class, 29 | // to represent inheritance to JHybridObject on C++ side 30 | super.updateNative(mHybridData) 31 | } 32 | 33 | /** 34 | * Call from a child class to initialize HybridData with a child. 35 | */ 36 | override fun updateNative(hybridData: HybridData) { 37 | mHybridData = hybridData 38 | } 39 | 40 | // Properties 41 | 42 | 43 | // Methods 44 | @DoNotStrip 45 | @Keep 46 | abstract fun write(buffer: ArrayBuffer): Promise 47 | 48 | @DoNotStrip 49 | @Keep 50 | abstract fun open(): Unit 51 | 52 | @DoNotStrip 53 | @Keep 54 | abstract fun close(): Unit 55 | 56 | private external fun initHybrid(): HybridData 57 | 58 | companion object { 59 | private const val TAG = "HybridOutputStreamSpec" 60 | init { 61 | try { 62 | Log.i(TAG, "Loading FastIO C++ library...") 63 | System.loadLibrary("FastIO") 64 | Log.i(TAG, "Successfully loaded FastIO C++ library!") 65 | } catch (e: Error) { 66 | Log.e(TAG, "Failed to load FastIO C++ library! Is it properly installed and linked? " + 67 | "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e) 68 | throw e 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/HybridStreamFactorySpec.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridStreamFactorySpec.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import android.util.Log 11 | import androidx.annotation.Keep 12 | import com.facebook.jni.HybridData 13 | import com.facebook.proguard.annotations.DoNotStrip 14 | import com.margelo.nitro.core.* 15 | 16 | /** 17 | * A Kotlin class representing the StreamFactory HybridObject. 18 | * Implement this abstract class to create Kotlin-based instances of StreamFactory. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") 23 | abstract class HybridStreamFactorySpec: HybridObject() { 24 | @DoNotStrip 25 | private var mHybridData: HybridData = initHybrid() 26 | 27 | init { 28 | // Pass this `HybridData` through to it's base class, 29 | // to represent inheritance to JHybridObject on C++ side 30 | super.updateNative(mHybridData) 31 | } 32 | 33 | /** 34 | * Call from a child class to initialize HybridData with a child. 35 | */ 36 | override fun updateNative(hybridData: HybridData) { 37 | mHybridData = hybridData 38 | } 39 | 40 | // Properties 41 | @get:DoNotStrip 42 | @get:Keep 43 | abstract val bufferSize: Double 44 | 45 | // Methods 46 | @DoNotStrip 47 | @Keep 48 | abstract fun createInputStream(path: String): HybridInputStreamSpec 49 | 50 | private external fun initHybrid(): HybridData 51 | 52 | companion object { 53 | private const val TAG = "HybridStreamFactorySpec" 54 | init { 55 | try { 56 | Log.i(TAG, "Loading FastIO C++ library...") 57 | System.loadLibrary("FastIO") 58 | Log.i(TAG, "Successfully loaded FastIO C++ library!") 59 | } catch (e: Error) { 60 | Log.e(TAG, "Failed to load FastIO C++ library! Is it properly installed and linked? " + 61 | "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e) 62 | throw e 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/HybridWebSocketManagerSpec.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridWebSocketManagerSpec.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import android.util.Log 11 | import androidx.annotation.Keep 12 | import com.facebook.jni.HybridData 13 | import com.facebook.proguard.annotations.DoNotStrip 14 | import com.margelo.nitro.core.* 15 | 16 | /** 17 | * A Kotlin class representing the WebSocketManager HybridObject. 18 | * Implement this abstract class to create Kotlin-based instances of WebSocketManager. 19 | */ 20 | @DoNotStrip 21 | @Keep 22 | @Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused") 23 | abstract class HybridWebSocketManagerSpec: HybridObject() { 24 | @DoNotStrip 25 | private var mHybridData: HybridData = initHybrid() 26 | 27 | init { 28 | // Pass this `HybridData` through to it's base class, 29 | // to represent inheritance to JHybridObject on C++ side 30 | super.updateNative(mHybridData) 31 | } 32 | 33 | /** 34 | * Call from a child class to initialize HybridData with a child. 35 | */ 36 | override fun updateNative(hybridData: HybridData) { 37 | mHybridData = hybridData 38 | } 39 | 40 | // Properties 41 | 42 | 43 | // Methods 44 | @DoNotStrip 45 | @Keep 46 | abstract fun create(url: String, protocols: Array): HybridWebSocketSpec 47 | 48 | private external fun initHybrid(): HybridData 49 | 50 | companion object { 51 | private const val TAG = "HybridWebSocketManagerSpec" 52 | init { 53 | try { 54 | Log.i(TAG, "Loading FastIO C++ library...") 55 | System.loadLibrary("FastIO") 56 | Log.i(TAG, "Successfully loaded FastIO C++ library!") 57 | } catch (e: Error) { 58 | Log.e(TAG, "Failed to load FastIO C++ library! Is it properly installed and linked? " + 59 | "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e) 60 | throw e 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/Metadata.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// Metadata.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import androidx.annotation.Keep 11 | import com.facebook.proguard.annotations.DoNotStrip 12 | import com.margelo.nitro.core.* 13 | 14 | /** 15 | * Represents the JavaScript object/struct "Metadata". 16 | */ 17 | @DoNotStrip 18 | @Keep 19 | data class Metadata( 20 | val name: String, 21 | val path: String, 22 | val root: String, 23 | val size: Double, 24 | val type: String, 25 | val lastModified: Double 26 | ) 27 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/NativeFilePickerOptions.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// NativeFilePickerOptions.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import androidx.annotation.Keep 11 | import com.facebook.proguard.annotations.DoNotStrip 12 | import com.margelo.nitro.core.* 13 | 14 | /** 15 | * Represents the JavaScript object/struct "NativeFilePickerOptions". 16 | */ 17 | @DoNotStrip 18 | @Keep 19 | data class NativeFilePickerOptions( 20 | val multiple: Boolean?, 21 | val startIn: String?, 22 | val extensions: Array?, 23 | val mimeTypes: Array? 24 | ) 25 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/RequestMethod.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// RequestMethod.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import androidx.annotation.Keep 11 | import com.facebook.proguard.annotations.DoNotStrip 12 | 13 | /** 14 | * Represents the JavaScript enum/union "RequestMethod". 15 | */ 16 | @DoNotStrip 17 | @Keep 18 | enum class RequestMethod { 19 | POST, 20 | GET; 21 | 22 | @DoNotStrip 23 | @Keep 24 | private val _ordinal = ordinal 25 | } 26 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/RequestOptions.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// RequestOptions.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import androidx.annotation.Keep 11 | import com.facebook.proguard.annotations.DoNotStrip 12 | import com.margelo.nitro.core.* 13 | 14 | /** 15 | * Represents the JavaScript object/struct "RequestOptions". 16 | */ 17 | @DoNotStrip 18 | @Keep 19 | data class RequestOptions( 20 | val url: String, 21 | val method: RequestMethod, 22 | val body: HybridInputStreamSpec? 23 | ) 24 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/WellKnownDirectory.kt: -------------------------------------------------------------------------------- 1 | /// 2 | /// WellKnownDirectory.kt 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | package com.margelo.nitro.fastio 9 | 10 | import androidx.annotation.Keep 11 | import com.facebook.proguard.annotations.DoNotStrip 12 | 13 | /** 14 | * Represents the JavaScript enum/union "WellKnownDirectory". 15 | */ 16 | @DoNotStrip 17 | @Keep 18 | enum class WellKnownDirectory { 19 | DESKTOP, 20 | DOCUMENTS, 21 | DOWNLOADS, 22 | MUSIC, 23 | PICTURES, 24 | VIDEOS; 25 | 26 | @DoNotStrip 27 | @Keep 28 | private val _ordinal = ordinal 29 | } 30 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/FastIO+autolinking.rb: -------------------------------------------------------------------------------- 1 | # 2 | # FastIO+autolinking.rb 3 | # This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | # https://github.com/mrousavy/nitro 5 | # Copyright © 2024 Marc Rousavy @ Margelo 6 | # 7 | 8 | # This is a Ruby script that adds all files generated by Nitrogen 9 | # to the given podspec. 10 | # 11 | # To use it, add this to your .podspec: 12 | # ```ruby 13 | # Pod::Spec.new do |spec| 14 | # # ... 15 | # 16 | # # Add all files generated by Nitrogen 17 | # load 'nitrogen/generated/ios/FastIO+autolinking.rb' 18 | # add_nitrogen_files(spec) 19 | # end 20 | # ``` 21 | 22 | def add_nitrogen_files(spec) 23 | Pod::UI.puts "[NitroModules] 🔥 FastIO is boosted by nitro!" 24 | 25 | spec.dependency "NitroModules" 26 | 27 | current_source_files = Array(spec.attributes_hash['source_files']) 28 | spec.source_files = current_source_files + [ 29 | # Generated cross-platform specs 30 | "nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}", 31 | # Generated bridges for the cross-platform specs 32 | "nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}", 33 | ] 34 | 35 | current_public_header_files = Array(spec.attributes_hash['public_header_files']) 36 | spec.public_header_files = current_public_header_files + [ 37 | # Generated specs 38 | "nitrogen/generated/shared/**/*.{h,hpp}", 39 | # Swift to C++ bridging helpers 40 | "nitrogen/generated/ios/FastIO-Swift-Cxx-Bridge.hpp" 41 | ] 42 | 43 | current_private_header_files = Array(spec.attributes_hash['private_header_files']) 44 | spec.private_header_files = current_private_header_files + [ 45 | # iOS specific specs 46 | "nitrogen/generated/ios/c++/**/*.{h,hpp}", 47 | ] 48 | 49 | current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {} 50 | spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({ 51 | # Use C++ 20 52 | "CLANG_CXX_LANGUAGE_STANDARD" => "c++20", 53 | # Enables C++ <-> Swift interop (by default it's only C) 54 | "SWIFT_OBJC_INTEROP_MODE" => "objcxx", 55 | # Enables stricter modular headers 56 | "DEFINES_MODULE" => "YES", 57 | }) 58 | end 59 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridDuplexStreamSpecSwift.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridDuplexStreamSpecSwift.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridDuplexStreamSpecSwift.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | } // namespace margelo::nitro::fastio 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridFileSystemSpecSwift.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridFileSystemSpecSwift.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridFileSystemSpecSwift.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | } // namespace margelo::nitro::fastio 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridInputStreamSpecSwift.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridInputStreamSpecSwift.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridInputStreamSpecSwift.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | } // namespace margelo::nitro::fastio 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridNetworkSpecSwift.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridNetworkSpecSwift.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridNetworkSpecSwift.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | } // namespace margelo::nitro::fastio 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridOutputStreamSpecSwift.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridOutputStreamSpecSwift.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridOutputStreamSpecSwift.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | } // namespace margelo::nitro::fastio 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridStreamFactorySpecSwift.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridStreamFactorySpecSwift.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridStreamFactorySpecSwift.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | } // namespace margelo::nitro::fastio 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridWebSocketManagerSpecSwift.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridWebSocketManagerSpecSwift.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridWebSocketManagerSpecSwift.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | } // namespace margelo::nitro::fastio 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/c++/HybridWebSocketSpecSwift.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridWebSocketSpecSwift.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridWebSocketSpecSwift.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | } // namespace margelo::nitro::fastio 12 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/Func_void.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Func_void.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import NitroModules 9 | 10 | /** 11 | * Wraps a Swift `(() -> Void)` as a class. 12 | * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. 13 | */ 14 | public final class Func_void { 15 | public typealias bridge = margelo.nitro.fastio.bridge.swift 16 | 17 | private let closure: (() -> Void) 18 | 19 | public init(_ closure: @escaping (() -> Void)) { 20 | self.closure = closure 21 | } 22 | 23 | @inline(__always) 24 | public func call() -> Void { 25 | self.closure() 26 | } 27 | 28 | /** 29 | * Casts this instance to a retained unsafe raw pointer. 30 | * This acquires one additional strong reference on the object! 31 | */ 32 | @inline(__always) 33 | public func toUnsafe() -> UnsafeMutableRawPointer { 34 | return Unmanaged.passRetained(self).toOpaque() 35 | } 36 | 37 | /** 38 | * Casts an unsafe pointer to a `Func_void`. 39 | * The pointer has to be a retained opaque `Unmanaged`. 40 | * This removes one strong reference from the object! 41 | */ 42 | @inline(__always) 43 | public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void { 44 | return Unmanaged.fromOpaque(pointer).takeRetainedValue() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/Func_void_double_std__string.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Func_void_double_std__string.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import NitroModules 9 | 10 | /** 11 | * Wraps a Swift `((_ code: Double, _ reason: String) -> Void)` as a class. 12 | * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. 13 | */ 14 | public final class Func_void_double_std__string { 15 | public typealias bridge = margelo.nitro.fastio.bridge.swift 16 | 17 | private let closure: ((_ code: Double, _ reason: String) -> Void) 18 | 19 | public init(_ closure: @escaping ((_ code: Double, _ reason: String) -> Void)) { 20 | self.closure = closure 21 | } 22 | 23 | @inline(__always) 24 | public func call(code: Double, reason: std.string) -> Void { 25 | self.closure(code, String(reason)) 26 | } 27 | 28 | /** 29 | * Casts this instance to a retained unsafe raw pointer. 30 | * This acquires one additional strong reference on the object! 31 | */ 32 | @inline(__always) 33 | public func toUnsafe() -> UnsafeMutableRawPointer { 34 | return Unmanaged.passRetained(self).toOpaque() 35 | } 36 | 37 | /** 38 | * Casts an unsafe pointer to a `Func_void_double_std__string`. 39 | * The pointer has to be a retained opaque `Unmanaged`. 40 | * This removes one strong reference from the object! 41 | */ 42 | @inline(__always) 43 | public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_double_std__string { 44 | return Unmanaged.fromOpaque(pointer).takeRetainedValue() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Func_void_std__exception_ptr.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import NitroModules 9 | 10 | /** 11 | * Wraps a Swift `((_ error: Error) -> Void)` as a class. 12 | * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. 13 | */ 14 | public final class Func_void_std__exception_ptr { 15 | public typealias bridge = margelo.nitro.fastio.bridge.swift 16 | 17 | private let closure: ((_ error: Error) -> Void) 18 | 19 | public init(_ closure: @escaping ((_ error: Error) -> Void)) { 20 | self.closure = closure 21 | } 22 | 23 | @inline(__always) 24 | public func call(error: std.exception_ptr) -> Void { 25 | self.closure(RuntimeError.from(cppError: error)) 26 | } 27 | 28 | /** 29 | * Casts this instance to a retained unsafe raw pointer. 30 | * This acquires one additional strong reference on the object! 31 | */ 32 | @inline(__always) 33 | public func toUnsafe() -> UnsafeMutableRawPointer { 34 | return Unmanaged.passRetained(self).toOpaque() 35 | } 36 | 37 | /** 38 | * Casts an unsafe pointer to a `Func_void_std__exception_ptr`. 39 | * The pointer has to be a retained opaque `Unmanaged`. 40 | * This removes one strong reference from the object! 41 | */ 42 | @inline(__always) 43 | public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__exception_ptr { 44 | return Unmanaged.fromOpaque(pointer).takeRetainedValue() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Func_void_std__shared_ptr_ArrayBuffer_.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import NitroModules 9 | 10 | /** 11 | * Wraps a Swift `((_ buffer: ArrayBufferHolder) -> Void)` as a class. 12 | * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. 13 | */ 14 | public final class Func_void_std__shared_ptr_ArrayBuffer_ { 15 | public typealias bridge = margelo.nitro.fastio.bridge.swift 16 | 17 | private let closure: ((_ buffer: ArrayBufferHolder) -> Void) 18 | 19 | public init(_ closure: @escaping ((_ buffer: ArrayBufferHolder) -> Void)) { 20 | self.closure = closure 21 | } 22 | 23 | @inline(__always) 24 | public func call(buffer: ArrayBufferHolder) -> Void { 25 | self.closure(buffer) 26 | } 27 | 28 | /** 29 | * Casts this instance to a retained unsafe raw pointer. 30 | * This acquires one additional strong reference on the object! 31 | */ 32 | @inline(__always) 33 | public func toUnsafe() -> UnsafeMutableRawPointer { 34 | return Unmanaged.passRetained(self).toOpaque() 35 | } 36 | 37 | /** 38 | * Casts an unsafe pointer to a `Func_void_std__shared_ptr_ArrayBuffer_`. 39 | * The pointer has to be a retained opaque `Unmanaged`. 40 | * This removes one strong reference from the object! 41 | */ 42 | @inline(__always) 43 | public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_ArrayBuffer_ { 44 | return Unmanaged.fromOpaque(pointer).takeRetainedValue() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/Func_void_std__string.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Func_void_std__string.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import NitroModules 9 | 10 | /** 11 | * Wraps a Swift `((_ message: String) -> Void)` as a class. 12 | * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. 13 | */ 14 | public final class Func_void_std__string { 15 | public typealias bridge = margelo.nitro.fastio.bridge.swift 16 | 17 | private let closure: ((_ message: String) -> Void) 18 | 19 | public init(_ closure: @escaping ((_ message: String) -> Void)) { 20 | self.closure = closure 21 | } 22 | 23 | @inline(__always) 24 | public func call(message: std.string) -> Void { 25 | self.closure(String(message)) 26 | } 27 | 28 | /** 29 | * Casts this instance to a retained unsafe raw pointer. 30 | * This acquires one additional strong reference on the object! 31 | */ 32 | @inline(__always) 33 | public func toUnsafe() -> UnsafeMutableRawPointer { 34 | return Unmanaged.passRetained(self).toOpaque() 35 | } 36 | 37 | /** 38 | * Casts an unsafe pointer to a `Func_void_std__string`. 39 | * The pointer has to be a retained opaque `Unmanaged`. 40 | * This removes one strong reference from the object! 41 | */ 42 | @inline(__always) 43 | public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__string { 44 | return Unmanaged.fromOpaque(pointer).takeRetainedValue() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Func_void_std__vector_std__string_.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import NitroModules 9 | 10 | /** 11 | * Wraps a Swift `((_ value: [String]) -> Void)` as a class. 12 | * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. 13 | */ 14 | public final class Func_void_std__vector_std__string_ { 15 | public typealias bridge = margelo.nitro.fastio.bridge.swift 16 | 17 | private let closure: ((_ value: [String]) -> Void) 18 | 19 | public init(_ closure: @escaping ((_ value: [String]) -> Void)) { 20 | self.closure = closure 21 | } 22 | 23 | @inline(__always) 24 | public func call(value: bridge.std__vector_std__string_) -> Void { 25 | self.closure(value.map({ __item in String(__item) })) 26 | } 27 | 28 | /** 29 | * Casts this instance to a retained unsafe raw pointer. 30 | * This acquires one additional strong reference on the object! 31 | */ 32 | @inline(__always) 33 | public func toUnsafe() -> UnsafeMutableRawPointer { 34 | return Unmanaged.passRetained(self).toOpaque() 35 | } 36 | 37 | /** 38 | * Casts an unsafe pointer to a `Func_void_std__vector_std__string_`. 39 | * The pointer has to be a retained opaque `Unmanaged`. 40 | * This removes one strong reference from the object! 41 | */ 42 | @inline(__always) 43 | public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__vector_std__string_ { 44 | return Unmanaged.fromOpaque(pointer).takeRetainedValue() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridDuplexStreamSpec.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridDuplexStreamSpec.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | /// See ``HybridDuplexStreamSpec`` 12 | public protocol HybridDuplexStreamSpec_protocol: AnyObject { 13 | // Properties 14 | var inputStream: (any HybridInputStreamSpec) { get set } 15 | var outputStream: (any HybridOutputStreamSpec) { get set } 16 | 17 | // Methods 18 | 19 | } 20 | 21 | /// See ``HybridDuplexStreamSpec`` 22 | public class HybridDuplexStreamSpec_base: HybridObjectSpec { 23 | private weak var cxxWrapper: HybridDuplexStreamSpec_cxx? = nil 24 | public func getCxxWrapper() -> HybridDuplexStreamSpec_cxx { 25 | #if DEBUG 26 | guard self is HybridDuplexStreamSpec else { 27 | fatalError("`self` is not a `HybridDuplexStreamSpec`! Did you accidentally inherit from `HybridDuplexStreamSpec_base` instead of `HybridDuplexStreamSpec`?") 28 | } 29 | #endif 30 | if let cxxWrapper = self.cxxWrapper { 31 | return cxxWrapper 32 | } else { 33 | let cxxWrapper = HybridDuplexStreamSpec_cxx(self as! HybridDuplexStreamSpec) 34 | self.cxxWrapper = cxxWrapper 35 | return cxxWrapper 36 | } 37 | } 38 | public var memorySize: Int { return 0 } 39 | } 40 | 41 | /** 42 | * A Swift base-protocol representing the DuplexStream HybridObject. 43 | * Implement this protocol to create Swift-based instances of DuplexStream. 44 | * ```swift 45 | * class HybridDuplexStream : HybridDuplexStreamSpec { 46 | * // ... 47 | * } 48 | * ``` 49 | */ 50 | public typealias HybridDuplexStreamSpec = HybridDuplexStreamSpec_protocol & HybridDuplexStreamSpec_base 51 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridFileSystemSpec.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridFileSystemSpec.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | /// See ``HybridFileSystemSpec`` 12 | public protocol HybridFileSystemSpec_protocol: AnyObject { 13 | // Properties 14 | 15 | 16 | // Methods 17 | func getMetadata(path: String) throws -> Metadata 18 | func getWellKnownDirectoryPath(directory: WellKnownDirectory) throws -> String 19 | func showOpenFilePicker(options: NativeFilePickerOptions?) throws -> Promise<[String]> 20 | } 21 | 22 | /// See ``HybridFileSystemSpec`` 23 | public class HybridFileSystemSpec_base: HybridObjectSpec { 24 | private weak var cxxWrapper: HybridFileSystemSpec_cxx? = nil 25 | public func getCxxWrapper() -> HybridFileSystemSpec_cxx { 26 | #if DEBUG 27 | guard self is HybridFileSystemSpec else { 28 | fatalError("`self` is not a `HybridFileSystemSpec`! Did you accidentally inherit from `HybridFileSystemSpec_base` instead of `HybridFileSystemSpec`?") 29 | } 30 | #endif 31 | if let cxxWrapper = self.cxxWrapper { 32 | return cxxWrapper 33 | } else { 34 | let cxxWrapper = HybridFileSystemSpec_cxx(self as! HybridFileSystemSpec) 35 | self.cxxWrapper = cxxWrapper 36 | return cxxWrapper 37 | } 38 | } 39 | public var memorySize: Int { return 0 } 40 | } 41 | 42 | /** 43 | * A Swift base-protocol representing the FileSystem HybridObject. 44 | * Implement this protocol to create Swift-based instances of FileSystem. 45 | * ```swift 46 | * class HybridFileSystem : HybridFileSystemSpec { 47 | * // ... 48 | * } 49 | * ``` 50 | */ 51 | public typealias HybridFileSystemSpec = HybridFileSystemSpec_protocol & HybridFileSystemSpec_base 52 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridInputStreamSpec.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridInputStreamSpec.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | /// See ``HybridInputStreamSpec`` 12 | public protocol HybridInputStreamSpec_protocol: AnyObject { 13 | // Properties 14 | 15 | 16 | // Methods 17 | func read() throws -> Promise 18 | func open() throws -> Void 19 | func close() throws -> Void 20 | } 21 | 22 | /// See ``HybridInputStreamSpec`` 23 | public class HybridInputStreamSpec_base: HybridObjectSpec { 24 | private weak var cxxWrapper: HybridInputStreamSpec_cxx? = nil 25 | public func getCxxWrapper() -> HybridInputStreamSpec_cxx { 26 | #if DEBUG 27 | guard self is HybridInputStreamSpec else { 28 | fatalError("`self` is not a `HybridInputStreamSpec`! Did you accidentally inherit from `HybridInputStreamSpec_base` instead of `HybridInputStreamSpec`?") 29 | } 30 | #endif 31 | if let cxxWrapper = self.cxxWrapper { 32 | return cxxWrapper 33 | } else { 34 | let cxxWrapper = HybridInputStreamSpec_cxx(self as! HybridInputStreamSpec) 35 | self.cxxWrapper = cxxWrapper 36 | return cxxWrapper 37 | } 38 | } 39 | public var memorySize: Int { return 0 } 40 | } 41 | 42 | /** 43 | * A Swift base-protocol representing the InputStream HybridObject. 44 | * Implement this protocol to create Swift-based instances of InputStream. 45 | * ```swift 46 | * class HybridInputStream : HybridInputStreamSpec { 47 | * // ... 48 | * } 49 | * ``` 50 | */ 51 | public typealias HybridInputStreamSpec = HybridInputStreamSpec_protocol & HybridInputStreamSpec_base 52 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridNetworkSpec.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridNetworkSpec.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | /// See ``HybridNetworkSpec`` 12 | public protocol HybridNetworkSpec_protocol: AnyObject { 13 | // Properties 14 | 15 | 16 | // Methods 17 | func request(opts: RequestOptions) throws -> Promise 18 | } 19 | 20 | /// See ``HybridNetworkSpec`` 21 | public class HybridNetworkSpec_base: HybridObjectSpec { 22 | private weak var cxxWrapper: HybridNetworkSpec_cxx? = nil 23 | public func getCxxWrapper() -> HybridNetworkSpec_cxx { 24 | #if DEBUG 25 | guard self is HybridNetworkSpec else { 26 | fatalError("`self` is not a `HybridNetworkSpec`! Did you accidentally inherit from `HybridNetworkSpec_base` instead of `HybridNetworkSpec`?") 27 | } 28 | #endif 29 | if let cxxWrapper = self.cxxWrapper { 30 | return cxxWrapper 31 | } else { 32 | let cxxWrapper = HybridNetworkSpec_cxx(self as! HybridNetworkSpec) 33 | self.cxxWrapper = cxxWrapper 34 | return cxxWrapper 35 | } 36 | } 37 | public var memorySize: Int { return 0 } 38 | } 39 | 40 | /** 41 | * A Swift base-protocol representing the Network HybridObject. 42 | * Implement this protocol to create Swift-based instances of Network. 43 | * ```swift 44 | * class HybridNetwork : HybridNetworkSpec { 45 | * // ... 46 | * } 47 | * ``` 48 | */ 49 | public typealias HybridNetworkSpec = HybridNetworkSpec_protocol & HybridNetworkSpec_base 50 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridOutputStreamSpec.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridOutputStreamSpec.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | /// See ``HybridOutputStreamSpec`` 12 | public protocol HybridOutputStreamSpec_protocol: AnyObject { 13 | // Properties 14 | 15 | 16 | // Methods 17 | func write(buffer: ArrayBufferHolder) throws -> Promise 18 | func open() throws -> Void 19 | func close() throws -> Void 20 | } 21 | 22 | /// See ``HybridOutputStreamSpec`` 23 | public class HybridOutputStreamSpec_base: HybridObjectSpec { 24 | private weak var cxxWrapper: HybridOutputStreamSpec_cxx? = nil 25 | public func getCxxWrapper() -> HybridOutputStreamSpec_cxx { 26 | #if DEBUG 27 | guard self is HybridOutputStreamSpec else { 28 | fatalError("`self` is not a `HybridOutputStreamSpec`! Did you accidentally inherit from `HybridOutputStreamSpec_base` instead of `HybridOutputStreamSpec`?") 29 | } 30 | #endif 31 | if let cxxWrapper = self.cxxWrapper { 32 | return cxxWrapper 33 | } else { 34 | let cxxWrapper = HybridOutputStreamSpec_cxx(self as! HybridOutputStreamSpec) 35 | self.cxxWrapper = cxxWrapper 36 | return cxxWrapper 37 | } 38 | } 39 | public var memorySize: Int { return 0 } 40 | } 41 | 42 | /** 43 | * A Swift base-protocol representing the OutputStream HybridObject. 44 | * Implement this protocol to create Swift-based instances of OutputStream. 45 | * ```swift 46 | * class HybridOutputStream : HybridOutputStreamSpec { 47 | * // ... 48 | * } 49 | * ``` 50 | */ 51 | public typealias HybridOutputStreamSpec = HybridOutputStreamSpec_protocol & HybridOutputStreamSpec_base 52 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridStreamFactorySpec.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridStreamFactorySpec.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | /// See ``HybridStreamFactorySpec`` 12 | public protocol HybridStreamFactorySpec_protocol: AnyObject { 13 | // Properties 14 | var bufferSize: Double { get } 15 | 16 | // Methods 17 | func createInputStream(path: String) throws -> (any HybridInputStreamSpec) 18 | } 19 | 20 | /// See ``HybridStreamFactorySpec`` 21 | public class HybridStreamFactorySpec_base: HybridObjectSpec { 22 | private weak var cxxWrapper: HybridStreamFactorySpec_cxx? = nil 23 | public func getCxxWrapper() -> HybridStreamFactorySpec_cxx { 24 | #if DEBUG 25 | guard self is HybridStreamFactorySpec else { 26 | fatalError("`self` is not a `HybridStreamFactorySpec`! Did you accidentally inherit from `HybridStreamFactorySpec_base` instead of `HybridStreamFactorySpec`?") 27 | } 28 | #endif 29 | if let cxxWrapper = self.cxxWrapper { 30 | return cxxWrapper 31 | } else { 32 | let cxxWrapper = HybridStreamFactorySpec_cxx(self as! HybridStreamFactorySpec) 33 | self.cxxWrapper = cxxWrapper 34 | return cxxWrapper 35 | } 36 | } 37 | public var memorySize: Int { return 0 } 38 | } 39 | 40 | /** 41 | * A Swift base-protocol representing the StreamFactory HybridObject. 42 | * Implement this protocol to create Swift-based instances of StreamFactory. 43 | * ```swift 44 | * class HybridStreamFactory : HybridStreamFactorySpec { 45 | * // ... 46 | * } 47 | * ``` 48 | */ 49 | public typealias HybridStreamFactorySpec = HybridStreamFactorySpec_protocol & HybridStreamFactorySpec_base 50 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridWebSocketManagerSpec.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridWebSocketManagerSpec.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | /// See ``HybridWebSocketManagerSpec`` 12 | public protocol HybridWebSocketManagerSpec_protocol: AnyObject { 13 | // Properties 14 | 15 | 16 | // Methods 17 | func create(url: String, protocols: [String]) throws -> (any HybridWebSocketSpec) 18 | } 19 | 20 | /// See ``HybridWebSocketManagerSpec`` 21 | public class HybridWebSocketManagerSpec_base: HybridObjectSpec { 22 | private weak var cxxWrapper: HybridWebSocketManagerSpec_cxx? = nil 23 | public func getCxxWrapper() -> HybridWebSocketManagerSpec_cxx { 24 | #if DEBUG 25 | guard self is HybridWebSocketManagerSpec else { 26 | fatalError("`self` is not a `HybridWebSocketManagerSpec`! Did you accidentally inherit from `HybridWebSocketManagerSpec_base` instead of `HybridWebSocketManagerSpec`?") 27 | } 28 | #endif 29 | if let cxxWrapper = self.cxxWrapper { 30 | return cxxWrapper 31 | } else { 32 | let cxxWrapper = HybridWebSocketManagerSpec_cxx(self as! HybridWebSocketManagerSpec) 33 | self.cxxWrapper = cxxWrapper 34 | return cxxWrapper 35 | } 36 | } 37 | public var memorySize: Int { return 0 } 38 | } 39 | 40 | /** 41 | * A Swift base-protocol representing the WebSocketManager HybridObject. 42 | * Implement this protocol to create Swift-based instances of WebSocketManager. 43 | * ```swift 44 | * class HybridWebSocketManager : HybridWebSocketManagerSpec { 45 | * // ... 46 | * } 47 | * ``` 48 | */ 49 | public typealias HybridWebSocketManagerSpec = HybridWebSocketManagerSpec_protocol & HybridWebSocketManagerSpec_base 50 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/HybridWebSocketSpec.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridWebSocketSpec.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import Foundation 9 | import NitroModules 10 | 11 | /// See ``HybridWebSocketSpec`` 12 | public protocol HybridWebSocketSpec_protocol: AnyObject { 13 | // Properties 14 | 15 | 16 | // Methods 17 | func send(message: String) throws -> Void 18 | func sendArrayBuffer(buffer: ArrayBufferHolder) throws -> Void 19 | func connect() throws -> Void 20 | func close(code: Double, reason: String) throws -> Void 21 | func ping() throws -> Void 22 | func onOpen(callback: @escaping ((_ selectedProtocol: String) -> Void)) throws -> Void 23 | func onClose(callback: @escaping ((_ code: Double, _ reason: String) -> Void)) throws -> Void 24 | func onError(callback: @escaping ((_ error: String) -> Void)) throws -> Void 25 | func onMessage(callback: @escaping ((_ message: String) -> Void)) throws -> Void 26 | func onArrayBuffer(callback: @escaping ((_ buffer: ArrayBufferHolder) -> Void)) throws -> Void 27 | } 28 | 29 | /// See ``HybridWebSocketSpec`` 30 | public class HybridWebSocketSpec_base: HybridObjectSpec { 31 | private weak var cxxWrapper: HybridWebSocketSpec_cxx? = nil 32 | public func getCxxWrapper() -> HybridWebSocketSpec_cxx { 33 | #if DEBUG 34 | guard self is HybridWebSocketSpec else { 35 | fatalError("`self` is not a `HybridWebSocketSpec`! Did you accidentally inherit from `HybridWebSocketSpec_base` instead of `HybridWebSocketSpec`?") 36 | } 37 | #endif 38 | if let cxxWrapper = self.cxxWrapper { 39 | return cxxWrapper 40 | } else { 41 | let cxxWrapper = HybridWebSocketSpec_cxx(self as! HybridWebSocketSpec) 42 | self.cxxWrapper = cxxWrapper 43 | return cxxWrapper 44 | } 45 | } 46 | public var memorySize: Int { return 0 } 47 | } 48 | 49 | /** 50 | * A Swift base-protocol representing the WebSocket HybridObject. 51 | * Implement this protocol to create Swift-based instances of WebSocket. 52 | * ```swift 53 | * class HybridWebSocket : HybridWebSocketSpec { 54 | * // ... 55 | * } 56 | * ``` 57 | */ 58 | public typealias HybridWebSocketSpec = HybridWebSocketSpec_protocol & HybridWebSocketSpec_base 59 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/Metadata.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// Metadata.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | import NitroModules 9 | 10 | /** 11 | * Represents an instance of `Metadata`, backed by a C++ struct. 12 | */ 13 | public typealias Metadata = margelo.nitro.fastio.Metadata 14 | 15 | public extension Metadata { 16 | private typealias bridge = margelo.nitro.fastio.bridge.swift 17 | 18 | /** 19 | * Create a new instance of `Metadata`. 20 | */ 21 | init(name: String, path: String, root: String, size: Double, type: String, lastModified: Double) { 22 | self.init(std.string(name), std.string(path), std.string(root), size, std.string(type), lastModified) 23 | } 24 | 25 | var name: String { 26 | @inline(__always) 27 | get { 28 | return String(self.__name) 29 | } 30 | @inline(__always) 31 | set { 32 | self.__name = std.string(newValue) 33 | } 34 | } 35 | 36 | var path: String { 37 | @inline(__always) 38 | get { 39 | return String(self.__path) 40 | } 41 | @inline(__always) 42 | set { 43 | self.__path = std.string(newValue) 44 | } 45 | } 46 | 47 | var root: String { 48 | @inline(__always) 49 | get { 50 | return String(self.__root) 51 | } 52 | @inline(__always) 53 | set { 54 | self.__root = std.string(newValue) 55 | } 56 | } 57 | 58 | var size: Double { 59 | @inline(__always) 60 | get { 61 | return self.__size 62 | } 63 | @inline(__always) 64 | set { 65 | self.__size = newValue 66 | } 67 | } 68 | 69 | var type: String { 70 | @inline(__always) 71 | get { 72 | return String(self.__type) 73 | } 74 | @inline(__always) 75 | set { 76 | self.__type = std.string(newValue) 77 | } 78 | } 79 | 80 | var lastModified: Double { 81 | @inline(__always) 82 | get { 83 | return self.__lastModified 84 | } 85 | @inline(__always) 86 | set { 87 | self.__lastModified = newValue 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/RequestMethod.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// RequestMethod.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | /** 9 | * Represents the JS union `RequestMethod`, backed by a C++ enum. 10 | */ 11 | public typealias RequestMethod = margelo.nitro.fastio.RequestMethod 12 | 13 | public extension RequestMethod { 14 | /** 15 | * Get a RequestMethod for the given String value, or 16 | * return `nil` if the given value was invalid/unknown. 17 | */ 18 | init?(fromString string: String) { 19 | switch string { 20 | case "POST": 21 | self = .post 22 | case "GET": 23 | self = .get 24 | default: 25 | return nil 26 | } 27 | } 28 | 29 | /** 30 | * Get the String value this RequestMethod represents. 31 | */ 32 | var stringValue: String { 33 | switch self { 34 | case .post: 35 | return "POST" 36 | case .get: 37 | return "GET" 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/ios/swift/WellKnownDirectory.swift: -------------------------------------------------------------------------------- 1 | /// 2 | /// WellKnownDirectory.swift 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | /** 9 | * Represents the JS union `WellKnownDirectory`, backed by a C++ enum. 10 | */ 11 | public typealias WellKnownDirectory = margelo.nitro.fastio.WellKnownDirectory 12 | 13 | public extension WellKnownDirectory { 14 | /** 15 | * Get a WellKnownDirectory for the given String value, or 16 | * return `nil` if the given value was invalid/unknown. 17 | */ 18 | init?(fromString string: String) { 19 | switch string { 20 | case "desktop": 21 | self = .desktop 22 | case "documents": 23 | self = .documents 24 | case "downloads": 25 | self = .downloads 26 | case "music": 27 | self = .music 28 | case "pictures": 29 | self = .pictures 30 | case "videos": 31 | self = .videos 32 | default: 33 | return nil 34 | } 35 | } 36 | 37 | /** 38 | * Get the String value this WellKnownDirectory represents. 39 | */ 40 | var stringValue: String { 41 | switch self { 42 | case .desktop: 43 | return "desktop" 44 | case .documents: 45 | return "documents" 46 | case .downloads: 47 | return "downloads" 48 | case .music: 49 | return "music" 50 | case .pictures: 51 | return "pictures" 52 | case .videos: 53 | return "videos" 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridCompressorFactorySpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridCompressorFactorySpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridCompressorFactorySpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridCompressorFactorySpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridMethod("create", &HybridCompressorFactorySpec::create); 18 | }); 19 | } 20 | 21 | } // namespace margelo::nitro::fastio 22 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridCompressorFactorySpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridCompressorFactorySpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #if __has_include() 11 | #include 12 | #else 13 | #error NitroModules cannot be found! Are you sure you installed NitroModules properly? 14 | #endif 15 | 16 | // Forward declaration of `HybridCompressorSpec` to properly resolve imports. 17 | namespace margelo::nitro::fastio { class HybridCompressorSpec; } 18 | // Forward declaration of `CompressionAlgorithm` to properly resolve imports. 19 | namespace margelo::nitro::fastio { enum class CompressionAlgorithm; } 20 | 21 | #include 22 | #include "HybridCompressorSpec.hpp" 23 | #include "CompressionAlgorithm.hpp" 24 | 25 | namespace margelo::nitro::fastio { 26 | 27 | using namespace margelo::nitro; 28 | 29 | /** 30 | * An abstract base class for `CompressorFactory` 31 | * Inherit this class to create instances of `HybridCompressorFactorySpec` in C++. 32 | * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. 33 | * @example 34 | * ```cpp 35 | * class HybridCompressorFactory: public HybridCompressorFactorySpec { 36 | * public: 37 | * HybridCompressorFactory(...): HybridObject(TAG) { ... } 38 | * // ... 39 | * }; 40 | * ``` 41 | */ 42 | class HybridCompressorFactorySpec: public virtual HybridObject { 43 | public: 44 | // Constructor 45 | explicit HybridCompressorFactorySpec(): HybridObject(TAG) { } 46 | 47 | // Destructor 48 | virtual ~HybridCompressorFactorySpec() { } 49 | 50 | public: 51 | // Properties 52 | 53 | 54 | public: 55 | // Methods 56 | virtual std::shared_ptr create(CompressionAlgorithm algorithm) = 0; 57 | 58 | protected: 59 | // Hybrid Setup 60 | void loadHybridMethods() override; 61 | 62 | protected: 63 | // Tag for logging 64 | static constexpr auto TAG = "CompressorFactory"; 65 | }; 66 | 67 | } // namespace margelo::nitro::fastio 68 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridCompressorSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridCompressorSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridCompressorSpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridCompressorSpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridMethod("compress", &HybridCompressorSpec::compress); 18 | prototype.registerHybridMethod("finalize", &HybridCompressorSpec::finalize); 19 | }); 20 | } 21 | 22 | } // namespace margelo::nitro::fastio 23 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridCompressorSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridCompressorSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #if __has_include() 11 | #include 12 | #else 13 | #error NitroModules cannot be found! Are you sure you installed NitroModules properly? 14 | #endif 15 | 16 | // Forward declaration of `ArrayBuffer` to properly resolve imports. 17 | namespace NitroModules { class ArrayBuffer; } 18 | 19 | #include 20 | 21 | namespace margelo::nitro::fastio { 22 | 23 | using namespace margelo::nitro; 24 | 25 | /** 26 | * An abstract base class for `Compressor` 27 | * Inherit this class to create instances of `HybridCompressorSpec` in C++. 28 | * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. 29 | * @example 30 | * ```cpp 31 | * class HybridCompressor: public HybridCompressorSpec { 32 | * public: 33 | * HybridCompressor(...): HybridObject(TAG) { ... } 34 | * // ... 35 | * }; 36 | * ``` 37 | */ 38 | class HybridCompressorSpec: public virtual HybridObject { 39 | public: 40 | // Constructor 41 | explicit HybridCompressorSpec(): HybridObject(TAG) { } 42 | 43 | // Destructor 44 | virtual ~HybridCompressorSpec() { } 45 | 46 | public: 47 | // Properties 48 | 49 | 50 | public: 51 | // Methods 52 | virtual std::shared_ptr compress(const std::shared_ptr& chunk) = 0; 53 | virtual std::shared_ptr finalize() = 0; 54 | 55 | protected: 56 | // Hybrid Setup 57 | void loadHybridMethods() override; 58 | 59 | protected: 60 | // Tag for logging 61 | static constexpr auto TAG = "Compressor"; 62 | }; 63 | 64 | } // namespace margelo::nitro::fastio 65 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridDuplexStreamSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridDuplexStreamSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridDuplexStreamSpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridDuplexStreamSpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridGetter("inputStream", &HybridDuplexStreamSpec::getInputStream); 18 | prototype.registerHybridSetter("inputStream", &HybridDuplexStreamSpec::setInputStream); 19 | prototype.registerHybridGetter("outputStream", &HybridDuplexStreamSpec::getOutputStream); 20 | prototype.registerHybridSetter("outputStream", &HybridDuplexStreamSpec::setOutputStream); 21 | }); 22 | } 23 | 24 | } // namespace margelo::nitro::fastio 25 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridDuplexStreamSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridDuplexStreamSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #if __has_include() 11 | #include 12 | #else 13 | #error NitroModules cannot be found! Are you sure you installed NitroModules properly? 14 | #endif 15 | 16 | // Forward declaration of `HybridInputStreamSpec` to properly resolve imports. 17 | namespace margelo::nitro::fastio { class HybridInputStreamSpec; } 18 | // Forward declaration of `HybridOutputStreamSpec` to properly resolve imports. 19 | namespace margelo::nitro::fastio { class HybridOutputStreamSpec; } 20 | 21 | #include 22 | #include "HybridInputStreamSpec.hpp" 23 | #include "HybridOutputStreamSpec.hpp" 24 | 25 | namespace margelo::nitro::fastio { 26 | 27 | using namespace margelo::nitro; 28 | 29 | /** 30 | * An abstract base class for `DuplexStream` 31 | * Inherit this class to create instances of `HybridDuplexStreamSpec` in C++. 32 | * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. 33 | * @example 34 | * ```cpp 35 | * class HybridDuplexStream: public HybridDuplexStreamSpec { 36 | * public: 37 | * HybridDuplexStream(...): HybridObject(TAG) { ... } 38 | * // ... 39 | * }; 40 | * ``` 41 | */ 42 | class HybridDuplexStreamSpec: public virtual HybridObject { 43 | public: 44 | // Constructor 45 | explicit HybridDuplexStreamSpec(): HybridObject(TAG) { } 46 | 47 | // Destructor 48 | virtual ~HybridDuplexStreamSpec() { } 49 | 50 | public: 51 | // Properties 52 | virtual std::shared_ptr getInputStream() = 0; 53 | virtual void setInputStream(const std::shared_ptr& inputStream) = 0; 54 | virtual std::shared_ptr getOutputStream() = 0; 55 | virtual void setOutputStream(const std::shared_ptr& outputStream) = 0; 56 | 57 | public: 58 | // Methods 59 | 60 | 61 | protected: 62 | // Hybrid Setup 63 | void loadHybridMethods() override; 64 | 65 | protected: 66 | // Tag for logging 67 | static constexpr auto TAG = "DuplexStream"; 68 | }; 69 | 70 | } // namespace margelo::nitro::fastio 71 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridFileSystemSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridFileSystemSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridFileSystemSpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridFileSystemSpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridMethod("getMetadata", &HybridFileSystemSpec::getMetadata); 18 | prototype.registerHybridMethod("getWellKnownDirectoryPath", &HybridFileSystemSpec::getWellKnownDirectoryPath); 19 | prototype.registerHybridMethod("showOpenFilePicker", &HybridFileSystemSpec::showOpenFilePicker); 20 | }); 21 | } 22 | 23 | } // namespace margelo::nitro::fastio 24 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridFileSystemSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridFileSystemSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #if __has_include() 11 | #include 12 | #else 13 | #error NitroModules cannot be found! Are you sure you installed NitroModules properly? 14 | #endif 15 | 16 | // Forward declaration of `Metadata` to properly resolve imports. 17 | namespace margelo::nitro::fastio { struct Metadata; } 18 | // Forward declaration of `WellKnownDirectory` to properly resolve imports. 19 | namespace margelo::nitro::fastio { enum class WellKnownDirectory; } 20 | // Forward declaration of `NativeFilePickerOptions` to properly resolve imports. 21 | namespace margelo::nitro::fastio { struct NativeFilePickerOptions; } 22 | 23 | #include "Metadata.hpp" 24 | #include 25 | #include "WellKnownDirectory.hpp" 26 | #include 27 | #include 28 | #include 29 | #include "NativeFilePickerOptions.hpp" 30 | 31 | namespace margelo::nitro::fastio { 32 | 33 | using namespace margelo::nitro; 34 | 35 | /** 36 | * An abstract base class for `FileSystem` 37 | * Inherit this class to create instances of `HybridFileSystemSpec` in C++. 38 | * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. 39 | * @example 40 | * ```cpp 41 | * class HybridFileSystem: public HybridFileSystemSpec { 42 | * public: 43 | * HybridFileSystem(...): HybridObject(TAG) { ... } 44 | * // ... 45 | * }; 46 | * ``` 47 | */ 48 | class HybridFileSystemSpec: public virtual HybridObject { 49 | public: 50 | // Constructor 51 | explicit HybridFileSystemSpec(): HybridObject(TAG) { } 52 | 53 | // Destructor 54 | virtual ~HybridFileSystemSpec() { } 55 | 56 | public: 57 | // Properties 58 | 59 | 60 | public: 61 | // Methods 62 | virtual Metadata getMetadata(const std::string& path) = 0; 63 | virtual std::string getWellKnownDirectoryPath(WellKnownDirectory directory) = 0; 64 | virtual std::shared_ptr>> showOpenFilePicker(const std::optional& options) = 0; 65 | 66 | protected: 67 | // Hybrid Setup 68 | void loadHybridMethods() override; 69 | 70 | protected: 71 | // Tag for logging 72 | static constexpr auto TAG = "FileSystem"; 73 | }; 74 | 75 | } // namespace margelo::nitro::fastio 76 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridInputStreamSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridInputStreamSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridInputStreamSpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridInputStreamSpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridMethod("read", &HybridInputStreamSpec::read); 18 | prototype.registerHybridMethod("open", &HybridInputStreamSpec::open); 19 | prototype.registerHybridMethod("close", &HybridInputStreamSpec::close); 20 | }); 21 | } 22 | 23 | } // namespace margelo::nitro::fastio 24 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridInputStreamSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridInputStreamSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #if __has_include() 11 | #include 12 | #else 13 | #error NitroModules cannot be found! Are you sure you installed NitroModules properly? 14 | #endif 15 | 16 | // Forward declaration of `ArrayBuffer` to properly resolve imports. 17 | namespace NitroModules { class ArrayBuffer; } 18 | 19 | #include 20 | #include 21 | 22 | namespace margelo::nitro::fastio { 23 | 24 | using namespace margelo::nitro; 25 | 26 | /** 27 | * An abstract base class for `InputStream` 28 | * Inherit this class to create instances of `HybridInputStreamSpec` in C++. 29 | * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. 30 | * @example 31 | * ```cpp 32 | * class HybridInputStream: public HybridInputStreamSpec { 33 | * public: 34 | * HybridInputStream(...): HybridObject(TAG) { ... } 35 | * // ... 36 | * }; 37 | * ``` 38 | */ 39 | class HybridInputStreamSpec: public virtual HybridObject { 40 | public: 41 | // Constructor 42 | explicit HybridInputStreamSpec(): HybridObject(TAG) { } 43 | 44 | // Destructor 45 | virtual ~HybridInputStreamSpec() { } 46 | 47 | public: 48 | // Properties 49 | 50 | 51 | public: 52 | // Methods 53 | virtual std::shared_ptr>> read() = 0; 54 | virtual void open() = 0; 55 | virtual void close() = 0; 56 | 57 | protected: 58 | // Hybrid Setup 59 | void loadHybridMethods() override; 60 | 61 | protected: 62 | // Tag for logging 63 | static constexpr auto TAG = "InputStream"; 64 | }; 65 | 66 | } // namespace margelo::nitro::fastio 67 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridNetworkSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridNetworkSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridNetworkSpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridNetworkSpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridMethod("request", &HybridNetworkSpec::request); 18 | }); 19 | } 20 | 21 | } // namespace margelo::nitro::fastio 22 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridNetworkSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridNetworkSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #if __has_include() 11 | #include 12 | #else 13 | #error NitroModules cannot be found! Are you sure you installed NitroModules properly? 14 | #endif 15 | 16 | // Forward declaration of `RequestOptions` to properly resolve imports. 17 | namespace margelo::nitro::fastio { struct RequestOptions; } 18 | 19 | #include 20 | #include "RequestOptions.hpp" 21 | 22 | namespace margelo::nitro::fastio { 23 | 24 | using namespace margelo::nitro; 25 | 26 | /** 27 | * An abstract base class for `Network` 28 | * Inherit this class to create instances of `HybridNetworkSpec` in C++. 29 | * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. 30 | * @example 31 | * ```cpp 32 | * class HybridNetwork: public HybridNetworkSpec { 33 | * public: 34 | * HybridNetwork(...): HybridObject(TAG) { ... } 35 | * // ... 36 | * }; 37 | * ``` 38 | */ 39 | class HybridNetworkSpec: public virtual HybridObject { 40 | public: 41 | // Constructor 42 | explicit HybridNetworkSpec(): HybridObject(TAG) { } 43 | 44 | // Destructor 45 | virtual ~HybridNetworkSpec() { } 46 | 47 | public: 48 | // Properties 49 | 50 | 51 | public: 52 | // Methods 53 | virtual std::shared_ptr> request(const RequestOptions& opts) = 0; 54 | 55 | protected: 56 | // Hybrid Setup 57 | void loadHybridMethods() override; 58 | 59 | protected: 60 | // Tag for logging 61 | static constexpr auto TAG = "Network"; 62 | }; 63 | 64 | } // namespace margelo::nitro::fastio 65 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridOutputStreamSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridOutputStreamSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridOutputStreamSpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridOutputStreamSpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridMethod("write", &HybridOutputStreamSpec::write); 18 | prototype.registerHybridMethod("open", &HybridOutputStreamSpec::open); 19 | prototype.registerHybridMethod("close", &HybridOutputStreamSpec::close); 20 | }); 21 | } 22 | 23 | } // namespace margelo::nitro::fastio 24 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridOutputStreamSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridOutputStreamSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #if __has_include() 11 | #include 12 | #else 13 | #error NitroModules cannot be found! Are you sure you installed NitroModules properly? 14 | #endif 15 | 16 | // Forward declaration of `ArrayBuffer` to properly resolve imports. 17 | namespace NitroModules { class ArrayBuffer; } 18 | 19 | #include 20 | #include 21 | 22 | namespace margelo::nitro::fastio { 23 | 24 | using namespace margelo::nitro; 25 | 26 | /** 27 | * An abstract base class for `OutputStream` 28 | * Inherit this class to create instances of `HybridOutputStreamSpec` in C++. 29 | * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. 30 | * @example 31 | * ```cpp 32 | * class HybridOutputStream: public HybridOutputStreamSpec { 33 | * public: 34 | * HybridOutputStream(...): HybridObject(TAG) { ... } 35 | * // ... 36 | * }; 37 | * ``` 38 | */ 39 | class HybridOutputStreamSpec: public virtual HybridObject { 40 | public: 41 | // Constructor 42 | explicit HybridOutputStreamSpec(): HybridObject(TAG) { } 43 | 44 | // Destructor 45 | virtual ~HybridOutputStreamSpec() { } 46 | 47 | public: 48 | // Properties 49 | 50 | 51 | public: 52 | // Methods 53 | virtual std::shared_ptr> write(const std::shared_ptr& buffer) = 0; 54 | virtual void open() = 0; 55 | virtual void close() = 0; 56 | 57 | protected: 58 | // Hybrid Setup 59 | void loadHybridMethods() override; 60 | 61 | protected: 62 | // Tag for logging 63 | static constexpr auto TAG = "OutputStream"; 64 | }; 65 | 66 | } // namespace margelo::nitro::fastio 67 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridStreamFactorySpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridStreamFactorySpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridStreamFactorySpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridStreamFactorySpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridGetter("bufferSize", &HybridStreamFactorySpec::getBufferSize); 18 | prototype.registerHybridMethod("createInputStream", &HybridStreamFactorySpec::createInputStream); 19 | }); 20 | } 21 | 22 | } // namespace margelo::nitro::fastio 23 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridStreamFactorySpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridStreamFactorySpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #if __has_include() 11 | #include 12 | #else 13 | #error NitroModules cannot be found! Are you sure you installed NitroModules properly? 14 | #endif 15 | 16 | // Forward declaration of `HybridInputStreamSpec` to properly resolve imports. 17 | namespace margelo::nitro::fastio { class HybridInputStreamSpec; } 18 | 19 | #include 20 | #include "HybridInputStreamSpec.hpp" 21 | #include 22 | 23 | namespace margelo::nitro::fastio { 24 | 25 | using namespace margelo::nitro; 26 | 27 | /** 28 | * An abstract base class for `StreamFactory` 29 | * Inherit this class to create instances of `HybridStreamFactorySpec` in C++. 30 | * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. 31 | * @example 32 | * ```cpp 33 | * class HybridStreamFactory: public HybridStreamFactorySpec { 34 | * public: 35 | * HybridStreamFactory(...): HybridObject(TAG) { ... } 36 | * // ... 37 | * }; 38 | * ``` 39 | */ 40 | class HybridStreamFactorySpec: public virtual HybridObject { 41 | public: 42 | // Constructor 43 | explicit HybridStreamFactorySpec(): HybridObject(TAG) { } 44 | 45 | // Destructor 46 | virtual ~HybridStreamFactorySpec() { } 47 | 48 | public: 49 | // Properties 50 | virtual double getBufferSize() = 0; 51 | 52 | public: 53 | // Methods 54 | virtual std::shared_ptr createInputStream(const std::string& path) = 0; 55 | 56 | protected: 57 | // Hybrid Setup 58 | void loadHybridMethods() override; 59 | 60 | protected: 61 | // Tag for logging 62 | static constexpr auto TAG = "StreamFactory"; 63 | }; 64 | 65 | } // namespace margelo::nitro::fastio 66 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridWebSocketManagerSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridWebSocketManagerSpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridWebSocketManagerSpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridMethod("create", &HybridWebSocketManagerSpec::create); 18 | }); 19 | } 20 | 21 | } // namespace margelo::nitro::fastio 22 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.hpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridWebSocketManagerSpec.hpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #pragma once 9 | 10 | #if __has_include() 11 | #include 12 | #else 13 | #error NitroModules cannot be found! Are you sure you installed NitroModules properly? 14 | #endif 15 | 16 | // Forward declaration of `HybridWebSocketSpec` to properly resolve imports. 17 | namespace margelo::nitro::fastio { class HybridWebSocketSpec; } 18 | 19 | #include 20 | #include "HybridWebSocketSpec.hpp" 21 | #include 22 | #include 23 | 24 | namespace margelo::nitro::fastio { 25 | 26 | using namespace margelo::nitro; 27 | 28 | /** 29 | * An abstract base class for `WebSocketManager` 30 | * Inherit this class to create instances of `HybridWebSocketManagerSpec` in C++. 31 | * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. 32 | * @example 33 | * ```cpp 34 | * class HybridWebSocketManager: public HybridWebSocketManagerSpec { 35 | * public: 36 | * HybridWebSocketManager(...): HybridObject(TAG) { ... } 37 | * // ... 38 | * }; 39 | * ``` 40 | */ 41 | class HybridWebSocketManagerSpec: public virtual HybridObject { 42 | public: 43 | // Constructor 44 | explicit HybridWebSocketManagerSpec(): HybridObject(TAG) { } 45 | 46 | // Destructor 47 | virtual ~HybridWebSocketManagerSpec() { } 48 | 49 | public: 50 | // Properties 51 | 52 | 53 | public: 54 | // Methods 55 | virtual std::shared_ptr create(const std::string& url, const std::vector& protocols) = 0; 56 | 57 | protected: 58 | // Hybrid Setup 59 | void loadHybridMethods() override; 60 | 61 | protected: 62 | // Tag for logging 63 | static constexpr auto TAG = "WebSocketManager"; 64 | }; 65 | 66 | } // namespace margelo::nitro::fastio 67 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/nitrogen/generated/shared/c++/HybridWebSocketSpec.cpp: -------------------------------------------------------------------------------- 1 | /// 2 | /// HybridWebSocketSpec.cpp 3 | /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. 4 | /// https://github.com/mrousavy/nitro 5 | /// Copyright © 2024 Marc Rousavy @ Margelo 6 | /// 7 | 8 | #include "HybridWebSocketSpec.hpp" 9 | 10 | namespace margelo::nitro::fastio { 11 | 12 | void HybridWebSocketSpec::loadHybridMethods() { 13 | // load base methods/properties 14 | HybridObject::loadHybridMethods(); 15 | // load custom methods/properties 16 | registerHybrids(this, [](Prototype& prototype) { 17 | prototype.registerHybridMethod("send", &HybridWebSocketSpec::send); 18 | prototype.registerHybridMethod("sendArrayBuffer", &HybridWebSocketSpec::sendArrayBuffer); 19 | prototype.registerHybridMethod("connect", &HybridWebSocketSpec::connect); 20 | prototype.registerHybridMethod("close", &HybridWebSocketSpec::close); 21 | prototype.registerHybridMethod("ping", &HybridWebSocketSpec::ping); 22 | prototype.registerHybridMethod("onOpen", &HybridWebSocketSpec::onOpen); 23 | prototype.registerHybridMethod("onClose", &HybridWebSocketSpec::onClose); 24 | prototype.registerHybridMethod("onError", &HybridWebSocketSpec::onError); 25 | prototype.registerHybridMethod("onMessage", &HybridWebSocketSpec::onMessage); 26 | prototype.registerHybridMethod("onArrayBuffer", &HybridWebSocketSpec::onArrayBuffer); 27 | }); 28 | } 29 | 30 | } // namespace margelo::nitro::fastio 31 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './types/fs' 2 | export * from './w3c/blob' 3 | export * from './w3c/fetch' 4 | export * from './w3c/fs' 5 | export * from './w3c/streams' 6 | export * from './w3c/ws' 7 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/native/fs.nitro.ts: -------------------------------------------------------------------------------- 1 | import { HybridObject, NitroModules } from 'react-native-nitro-modules' 2 | 3 | export type Metadata = { 4 | name: string 5 | path: string 6 | root: string 7 | size: number 8 | type: string 9 | lastModified: number 10 | } 11 | 12 | type WellKnownDirectory = 'desktop' | 'documents' | 'downloads' | 'music' | 'pictures' | 'videos' 13 | 14 | export type NativeFilePickerOptions = { 15 | multiple?: boolean 16 | startIn?: string 17 | 18 | extensions?: string[] 19 | mimeTypes?: string[] 20 | } 21 | 22 | interface FileSystem extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> { 23 | getMetadata(path: string): Metadata 24 | getWellKnownDirectoryPath(directory: WellKnownDirectory): string 25 | 26 | showOpenFilePicker(options?: NativeFilePickerOptions): Promise 27 | } 28 | 29 | export const FileSystem = NitroModules.createHybridObject('FileSystem') 30 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/native/network.nitro.ts: -------------------------------------------------------------------------------- 1 | import { HybridObject, NitroModules } from 'react-native-nitro-modules' 2 | 3 | import { InputStream } from './streams.nitro' 4 | 5 | export type RequestMethod = 'POST' | 'GET' 6 | 7 | export type RequestOptions = { 8 | url: string 9 | method: RequestMethod 10 | body?: InputStream 11 | } 12 | 13 | export interface Network extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> { 14 | request(opts: RequestOptions): Promise 15 | } 16 | 17 | export const Network = NitroModules.createHybridObject('Network') 18 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/native/streams.nitro.ts: -------------------------------------------------------------------------------- 1 | import { getHybridObjectConstructor, HybridObject, NitroModules } from 'react-native-nitro-modules' 2 | 3 | export interface InputStream extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> { 4 | read(): Promise 5 | 6 | open(): void 7 | close(): void 8 | } 9 | 10 | export interface OutputStream extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> { 11 | write(buffer: ArrayBuffer): Promise 12 | 13 | open(): void 14 | close(): void 15 | } 16 | 17 | interface DuplexStream extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> { 18 | inputStream: InputStream 19 | outputStream: OutputStream 20 | } 21 | 22 | export const DuplexStream = getHybridObjectConstructor('DuplexStream') 23 | 24 | interface StreamFactory extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> { 25 | readonly bufferSize: number 26 | createInputStream(path: string): InputStream 27 | } 28 | 29 | export const StreamFactory = NitroModules.createHybridObject('StreamFactory') 30 | 31 | export type CompressionAlgorithm = 'gzip' | 'deflate' | 'deflate-raw' 32 | 33 | interface CompressorFactory extends HybridObject<{ ios: 'c++'; android: 'c++' }> { 34 | create(algorithm: CompressionAlgorithm): Compressor 35 | } 36 | 37 | interface Compressor extends HybridObject<{ ios: 'c++'; android: 'c++' }> { 38 | compress(chunk: ArrayBuffer): ArrayBuffer 39 | finalize(): ArrayBuffer 40 | } 41 | 42 | export const CompressorFactory = 43 | NitroModules.createHybridObject('CompressorFactory') 44 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/native/ws.nitro.ts: -------------------------------------------------------------------------------- 1 | import { HybridObject, NitroModules } from 'react-native-nitro-modules' 2 | 3 | export interface WebSocket extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> { 4 | send(message: string): void 5 | sendArrayBuffer(buffer: ArrayBuffer): void 6 | 7 | connect(): void 8 | close(code: number, reason: string): void 9 | ping(): void 10 | 11 | onOpen(callback: (selectedProtocol: string) => void): void 12 | onClose(callback: (code: number, reason: string) => void): void 13 | onError(callback: (error: string) => void): void 14 | 15 | onMessage(callback: (message: string) => void): void 16 | onArrayBuffer(callback: (buffer: ArrayBuffer) => void): void 17 | } 18 | 19 | export interface WebSocketManager extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> { 20 | create(url: string, protocols: string[]): WebSocket 21 | } 22 | 23 | export const WebSocketManager = 24 | NitroModules.createHybridObject('WebSocketManager') 25 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/types/fs.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Additional types for File System Access API that are currently not available in TypeScript. 3 | * This is because they are not supported by more than one browser engine. 4 | */ 5 | 6 | export {} 7 | 8 | export type WellKnownDirectory = 9 | | 'desktop' 10 | | 'documents' 11 | | 'downloads' 12 | | 'music' 13 | | 'pictures' 14 | | 'videos' 15 | export type FileExtension = `.${string}` 16 | export type MIMEType = `${string}/${string}` 17 | 18 | export interface FilePickerAcceptType { 19 | /** 20 | * @default "" 21 | */ 22 | description?: string | undefined 23 | accept: Record | undefined 24 | } 25 | 26 | export interface FilePickerOptions { 27 | types?: FilePickerAcceptType[] | undefined 28 | /** 29 | * @default false 30 | */ 31 | excludeAcceptAllOption?: boolean | undefined 32 | startIn?: WellKnownDirectory | /* | FileSystemHandle */ undefined 33 | id?: string | undefined 34 | } 35 | 36 | export interface OpenFilePickerOptions extends FilePickerOptions { 37 | /** 38 | * @default false 39 | */ 40 | multiple?: boolean | undefined 41 | } 42 | 43 | export interface SaveFilePickerOptions extends FilePickerOptions { 44 | suggestedName?: string | undefined 45 | } 46 | 47 | export type FileSystemPermissionMode = 'read' | 'readwrite' 48 | 49 | export interface DirectoryPickerOptions { 50 | id?: string | undefined 51 | startIn?: WellKnownDirectory /* | FileSystemHandle */ | undefined 52 | /** 53 | * @default "read" 54 | */ 55 | mode?: FileSystemPermissionMode | undefined 56 | } 57 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/w3c/blob.ts: -------------------------------------------------------------------------------- 1 | import { ReadableStream } from './streams' 2 | import { TextDecoder } from './text' 3 | 4 | export class Blob implements globalThis.Blob { 5 | private parts: Array 6 | 7 | readonly type: string 8 | 9 | protected _size: number 10 | get size(): number { 11 | return this._size 12 | } 13 | 14 | constructor(parts: Array = [], options: BlobPropertyBag = {}) { 15 | this.parts = parts 16 | this.type = options?.type?.toLowerCase() || '' 17 | this._size = calculateSize(parts) 18 | } 19 | 20 | slice(): Blob { 21 | throw new Error('Not implemented') 22 | } 23 | 24 | stream() { 25 | const streams = this.parts.map((part) => { 26 | if (part instanceof Blob) { 27 | return part.stream() 28 | } 29 | return new ReadableStream({ 30 | start(controller) { 31 | // tbd: handle all types and convert to Uint8Array 32 | // @ts-ignore 33 | controller.enqueue(part) 34 | controller.close() 35 | }, 36 | }) 37 | }) 38 | 39 | return new ReadableStream({ 40 | async start(controller) { 41 | try { 42 | for (const stream of streams) { 43 | for await (const chunk of stream) { 44 | controller.enqueue(chunk) 45 | } 46 | } 47 | controller.close() 48 | } catch (error) { 49 | controller.error(error) 50 | } 51 | }, 52 | }) 53 | } 54 | 55 | async arrayBuffer() { 56 | const view = await this.bytes() 57 | return view.buffer 58 | } 59 | 60 | async bytes() { 61 | const result = new ArrayBuffer(this.size) 62 | const view = new Uint8Array(result) 63 | 64 | let offset = 0 65 | for await (const chunk of this.stream()) { 66 | view.set(chunk, offset) 67 | offset += chunk.length 68 | } 69 | 70 | return view 71 | } 72 | 73 | async text() { 74 | const buffer = await this.bytes() 75 | return new TextDecoder().decode(buffer) 76 | } 77 | 78 | get [Symbol.toStringTag](): string { 79 | return 'Blob' 80 | } 81 | } 82 | 83 | // tbd: verify this 84 | function calculateSize(parts: Array): number { 85 | return parts.reduce((acc, part) => { 86 | if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) { 87 | return acc + part.byteLength 88 | } 89 | if (part instanceof Blob) { 90 | return acc + part.size 91 | } 92 | if (typeof part === 'string') { 93 | return acc + new TextEncoder().encode(part).length 94 | } 95 | return acc 96 | }, 0) 97 | } 98 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/w3c/fetch.ts: -------------------------------------------------------------------------------- 1 | import { Network, RequestMethod } from '../native/network.nitro' 2 | import { Blob } from './blob' 3 | import { File } from './fs' 4 | import { fromReadableStream, ReadableStream } from './streams' 5 | 6 | export function fetch( 7 | url: string, 8 | { body, method }: { body: ReadableStream | Blob | File; method: RequestMethod } 9 | ) { 10 | const nativeBody = body instanceof Blob || body instanceof File ? body.stream() : body 11 | return Network.request({ method, url, body: fromReadableStream(nativeBody) }) 12 | } 13 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/w3c/streams.ts: -------------------------------------------------------------------------------- 1 | import { ReadableStream, TransformStream, WritableStream } from 'web-streams-polyfill' 2 | 3 | import { CompressorFactory, DuplexStream, InputStream, OutputStream } from '../native/streams.nitro' 4 | 5 | export const toReadableStream = (inputStream: InputStream) => { 6 | const stream = new ReadableStream({ 7 | start() { 8 | inputStream.open() 9 | }, 10 | async pull(controller) { 11 | const buffer = await inputStream.read() 12 | if (buffer.byteLength == 0) { 13 | controller.close() 14 | return 15 | } 16 | 17 | const chunk = new Uint8Array(buffer) 18 | controller.enqueue(chunk) 19 | }, 20 | cancel() { 21 | inputStream.close() 22 | }, 23 | }) 24 | 25 | return stream 26 | } 27 | 28 | export const toWritableStream = (outputStream: OutputStream) => { 29 | return new WritableStream({ 30 | start() { 31 | outputStream.open() 32 | }, 33 | async write(chunk: Uint8Array) { 34 | if (chunk.byteLength === 0) { 35 | return 36 | } 37 | await outputStream.write(chunk.buffer) 38 | }, 39 | close() { 40 | outputStream.close() 41 | }, 42 | abort() { 43 | outputStream.close() 44 | }, 45 | }) 46 | } 47 | 48 | export const fromReadableStream = (stream: ReadableStream): InputStream => { 49 | const duplexStream = new DuplexStream() 50 | 51 | const writableStream = toWritableStream(duplexStream.outputStream) 52 | stream.pipeTo(writableStream) 53 | 54 | return duplexStream.inputStream 55 | } 56 | 57 | export class CompressionStream implements globalThis.CompressionStream { 58 | readonly readable: ReadableStream 59 | readonly writable: WritableStream 60 | 61 | constructor(format: CompressionFormat) { 62 | const compressor = CompressorFactory.create(format) 63 | 64 | const { readable, writable } = new TransformStream({ 65 | transform(chunk, controller) { 66 | const compressedData = compressor.compress(chunk.buffer) 67 | controller.enqueue(new Uint8Array(compressedData)) 68 | }, 69 | flush(controller) { 70 | const finalData = compressor.finalize() 71 | if (finalData.byteLength > 0) { 72 | controller.enqueue(new Uint8Array(finalData)) 73 | } 74 | }, 75 | }) 76 | 77 | this.readable = readable 78 | this.writable = writable 79 | } 80 | } 81 | 82 | export { ReadableStream, TransformStream, WritableStream } 83 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/src/w3c/text.ts: -------------------------------------------------------------------------------- 1 | export { TextDecoder } from '@bacons/text-decoder' 2 | 3 | export const TextEncoder = globalThis.TextEncoder 4 | -------------------------------------------------------------------------------- /packages/react-native-fast-io/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "paths": { 5 | "event-target-shim": ["./node_modules/event-target-shim"], 6 | }, 7 | "lib": ["es2020", "dom", "DOM.AsyncIterable"] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@react-native/typescript-config/tsconfig.json" 3 | } 4 | --------------------------------------------------------------------------------