RonRadtke / react-native-blob-util

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
754 stars 129 forks source link

Crash when readStream on IOS #356

Open tsogzark opened 5 months ago

tsogzark commented 5 months ago

Reproduce

I met the issue when i use this function to read a 300MB file on ios and when I read a 3MB it works well. It works well on android when read 300MB file, too.

   public splitLargeFile = async (localPath: string) => {
        let chunkCount = 0;
        const basename = localPath.split('/').pop();
        const bufferSize = 1024 * 900;
        RNFetchBlob.fs.readStream(
            localPath,
            'base64',
            bufferSize
        )
        .then((ifstream) => {
            ifstream.open();
            ifstream.onData(chunk => {
                chunkCount += 1;
                console.log(`${basename} chunk ${chunkCount*bufferSize}`);
            });
           ifstream.onError(err => {
                console.log('oops', err)
            });
            ifstream.onEnd(() => {
                console.log("End")
            });
        })
    }

Error

 LOG  2afae907f0696430905e416aca57f2ce.MP4 chunk 157593600
 LOG  2afae907f0696430905e416aca57f2ce.MP4 chunk 158515200
 LOG  oops [Error: Failed to convert data to 'base64' encoded string, this might due to the source data is not able to convert using this encoding. source = Failed to grow buffer]
 WARN  Failed to convert data to 'base64' encoded string, this might due to the source data is not able to convert using this encoding. source = Failed to grow buffer
 WARN  Failed to convert data to 'base64' encoded string, this might due to the source data is not able to convert using this encoding. source = Failed to grow buffer

log source

https://github.com/RonRadtke/react-native-blob-util/blob/618685faafaef005e3aabbf13933ee2767f9f2b5/ios/ReactNativeBlobUtilFS.mm#L271

ivaniuk7531 commented 6 days ago

I have the same error. @tsogzark, did you fix it?

tsogzark commented 1 day ago

I have the same error. @tsogzark, did you fix it?

I split the file into smaller chunks for transmission.