Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

RNFetchBlob.fs.readFile error while ReadStream and Exists works on Android #450

Closed
@easychen

Description

@easychen
  • please provide the version of installed library and RN project.

"react": "16.0.0-alpha.12",
"react-native": "0.46.4",
"react-native-fetch-blob": "^0.10.6",

  • a sample code snippet/repository is very helpful to spotting the problem.
const indexfile = "/data/user/0/com.h2read/files/h2index.json"; 
console.log( "index file= [" + indexfile +"]" );          
            RNFetchBlob.fs.exists(indexfile)
            .then((exist) => {
               
                if(exist)
                {
                    console.log("index file exists");
                    
                    RNFetchBlob.fs.readFile( indexfile ).then( (content) =>{
                        console.log( content );
                    }).catch((err) => { console.log( err ) });
                    
                    
                }
                else
                {
                    console.log("index file NOT exists");
                    //this._append_to_index( null );
                }
            })
            .catch((err) => { console.log( err ) })

cause some errors:

08-01 11:39:54.806 11266 13954 I ReactNativeJS: index file= [/data/user/0/com.h2read/files/h2index.j
son]
08-01 11:39:54.810 11266 13954 I ReactNativeJS: index file exists
08-01 11:39:54.812 11266 13954 I ReactNativeJS: { [Error: Attempt to invoke virtual method 'java.lan
g.String java.lang.String.toLowerCase()' on a null object reference] framesToPop: 1, code: 'ReadFile
 Error' }

But change to ReadStream , it works fine.

const indexfile = "/data/user/0/com.h2read/files/h2index.json"; 
console.log( "index file= [" + indexfile +"]" );

            
            RNFetchBlob.fs.exists(indexfile)
            .then((exist) => {
               
                if(exist)
                {
                    console.log("index file exists");
                    

                    
                    RNFetchBlob.fs.readStream( indexfile )
                    .then((stream) => {
                        let data = ''
                        stream.open()
                        stream.onData((chunk) => {
                            data += chunk
                        })
                        stream.onEnd(() => {
                            console.log(data)
                        })
                    }).catch((err) => { console.log( err ) });
                }
                else
                {
                    console.log("index file NOT exists");

                }
            })
            .catch((err) => { console.log( err ) })

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions