apache / apache/cordova-plugin-file

Calling FileWrite.write returns Type Error

Open
#636 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
744
Forks
754
Avg merge
3d 4h
Merged PRs (30d)
1

Description

# Bug Report

## Problem
I got this error when trying to write a binary string into file.

```javascript
this._realReader.readAsArrayBuffer is not a function.
(In 'this._realReader.readAsArrayBuffer(file)',
'this._realReader.readAsArrayBuffer' is undefined)
```
The error is thrown at FileReader.js, line 302.

``` javascript
FileReader.prototype.readAsArrayBuffer = function (file) {
if (initRead(this, file)) {
return this._realReader.readAsArrayBuffer(file);
}
const totalSize = file.end - file.start;
readSuccessCallback.bind(this)('readAsArrayBuffer', null, file.start, totalSize, function (r) {
const resultArray = (this._progress === 0 ? new Uint8Array(totalSize) : new Uint8Array(this._result));
resultArray.set(new Uint8Array(r), this._progress);
this._result = resultArray.buffer;
}.bind(this));
};
```

Here is how I call the FileWriter in my code:
```javascript
writeBlobToFile = (file: FileEntry, blob): angular.IPromise => {
return this.$q((resolve, reject) => {
file.createWriter((fileWriter) => {
fileWriter.write(blob);
fileWriter.onwriteend = resolve;
fileWriter.onerror = reject;
}, reject);
});
};
```

### Environment, Platform, Device
iOS 17.6 and iOS 18.0
iPhone 13 Plus

### Version information
cordova-plugin-file version 8.1.0
cordova-ios version 7.1.0

Contributor guide

Open the contributing guide

Research direction

Start at FileReader.js line 302 and trace how _realReader is initialized for iOS 17.6 and 18.0. Reproduce the FileWriter.write(blob) call from the issue, then verify that writing the binary blob completes without the readAsArrayBuffer TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.