writeFile returning success after writing 0 bytes
See original GitHub issueHello! Thank you for the very useful library. I have run into some trouble
- RN: 0.56.0
- rn-fetch-blob: 0.10.13
- iOS simulator
fs.writeFile with base64 data is returning without error, but writing zero bytes to the file
this.svg.toDataURL((data) => {
console.log(data);
const qrFile = RNFetchBlob.fs.dirs.CacheDir + '/qrbadge.png';
RNFetchBlob.fs.writeFile(qrFile, data, 'base64')
.then((len) => {
console.log('qr image to ' + qrFile + ' with len ' + len);
self.setState({qrImage: qrFile});
})
.catch((reason) => {
console.log('ex: ' + reason);
})
});
On the console I see:
[base64 data which I’ve pasted online and it yields the PNG image as expected]
qr image to /Users/daviddaeschler/Library/Developer/CoreSimulator/Devices/90DDC9E1-05D6-43C0-BAB2-603A9BDB341A/data/Containers/Data/Application/D383B543-0DD3-4663-A791-8DA07BD6A15B/Library/Caches/qrbadge.png with len 0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:10
Top Results From Across the Web
WriteFile returns 0 but writes bytes - MSDN - Microsoft
hello. I am using a thread environment to write and read asynchronically from a com port: Here is the logic: 1. try to...
Read more >Node Js writeFile always return 0 bytes when looping through ...
I have about more than 7.000 Base64 data that I want to save into a file using NodeJs, I can do this just...
Read more >WriteFile() returns 1, but writes 0 bytes
I am using WriteFile() to write to a serial port on an embedded CE device without overlapping. Very intermittantly, WriteFile() will return 0...
Read more >write
If write() is interrupted by a signal after it successfully writes some data, it will return the number of bytes written. If the...
Read more >write(2): to file descriptor - Linux man page - Die.net
If count is zero and fd refers to a regular file, then write() may return a failure status if one of the errors...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I figured this out. The base64 output from the other library I’m using was adding newline chars to the output. This must’ve caused the iOS writeFile method to silently fail to decode the base64.
It looks like line breaks in base64 data are widely accepted, so I guess a fix for the problem at the rn-fetch-blob level might be simply to strip line breaks before feeding it to NSData for decoding.
Thank you so much! I’ve been struggling on this for hours