Skip to content

readStream error with utf8 file containing arabic #341

@alainib

Description

@alainib

When i write arabic content and try to read them i get this error :

  readStream error Error: Failed to convert data to utf8 encoded string. This might be because this encoding cannot be used for this data.

both call are made with 'utf8' param

export async function writeStream(path, content, encoding = "utf8") {
  return new Promise(function(resolve, reject) {
	RNFetchBlob.fs.writeFile(path, "", encoding).then(res => {
	  RNFetchBlob.fs.writeStream(path, encoding).then(ofstream => {
		ofstream.write(content);
		ofstream.close();
		return resolve(true);
	  });
	});
  });
}


export async function readStream(path, encoding = "utf8") {
  let data = "";

  return new Promise(function(resolve, reject) {
	RNFetchBlob.fs.readStream(path, encoding, 102400).then(ifstream => {
	  ifstream.open();
	  ifstream.onData(chunk => {
		data += chunk;
	  });
	  ifstream.onError(err => {
		console.warn("readStream error", err);
		return resolve(false);
	  });
	  ifstream.onEnd(() => {
		return resolve(data);
	  });
	});
  });
}

Version :
"rn-fetch-blob": {
"version": "0.10.15",
"resolved": "https://registry.npmjs.org/rn-fetch-blob/-/rn-fetch-blob-0.10.15.tgz",
}

Any tips ?
thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions