You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Mobile: Fixes #4268: Fix "Not implemented" error when downloading resources with S3 sync target (#4279)
Since the RNFetchBlob API doesn't support writing binary data directly it creates a custom Writable which is doing the base64 encoding per chunk. This also fixes a problem with the S3 synchronization code using the shim.fsDriver().writeBinaryFile(). Tested with AVD Android 10.0 target. Signed-off-by: Jan Blunck <jblunck@users.noreply.github.com>
This commit is contained in:
@ -44,3 +44,6 @@ LogBox.ignoreLogs([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
AppRegistry.registerComponent('Joplin', () => Root);
|
AppRegistry.registerComponent('Joplin', () => Root);
|
||||||
|
|
||||||
|
// Using streams on react-native requires to polyfill process.nextTick()
|
||||||
|
global.process.nextTick = setImmediate;
|
||||||
|
21
packages/app-mobile/package-lock.json
generated
21
packages/app-mobile/package-lock.json
generated
@ -8379,6 +8379,27 @@
|
|||||||
"emitter-component": "^1.1.1"
|
"emitter-component": "^1.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"stream-browserify": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA==",
|
||||||
|
"requires": {
|
||||||
|
"inherits": "~2.0.4",
|
||||||
|
"readable-stream": "^3.5.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"readable-stream": {
|
||||||
|
"version": "3.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
|
||||||
|
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
|
||||||
|
"requires": {
|
||||||
|
"inherits": "^2.0.3",
|
||||||
|
"string_decoder": "^1.1.1",
|
||||||
|
"util-deprecate": "^1.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"stream-buffers": {
|
"stream-buffers": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/stream-buffers/-/stream-buffers-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/stream-buffers/-/stream-buffers-2.2.0.tgz",
|
||||||
|
@ -53,14 +53,15 @@
|
|||||||
"redux": "4.0.0",
|
"redux": "4.0.0",
|
||||||
"rn-fetch-blob": "^0.12.0",
|
"rn-fetch-blob": "^0.12.0",
|
||||||
"stream": "0.0.2",
|
"stream": "0.0.2",
|
||||||
|
"stream-browserify": "^3.0.0",
|
||||||
"string-natural-compare": "^2.0.2",
|
"string-natural-compare": "^2.0.2",
|
||||||
"timers": "^0.1.1",
|
"timers": "^0.1.1",
|
||||||
"valid-url": "^1.0.9"
|
"valid-url": "^1.0.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@joplin/tools": "^1.0.9",
|
|
||||||
"@babel/core": "^7.11.6",
|
"@babel/core": "^7.11.6",
|
||||||
"@babel/runtime": "^7.11.2",
|
"@babel/runtime": "^7.11.2",
|
||||||
|
"@joplin/tools": "^1.0.9",
|
||||||
"@types/node": "^14.14.6",
|
"@types/node": "^14.14.6",
|
||||||
"@types/react": "^16.9.55",
|
"@types/react": "^16.9.55",
|
||||||
"execa": "^4.0.0",
|
"execa": "^4.0.0",
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
const RNFS = require('react-native-fs');
|
const RNFS = require('react-native-fs');
|
||||||
const FsDriverBase = require('@joplin/lib/fs-driver-base').default;
|
const FsDriverBase = require('@joplin/lib/fs-driver-base').default;
|
||||||
const RNFetchBlob = require('rn-fetch-blob').default;
|
const RNFetchBlob = require('rn-fetch-blob').default;
|
||||||
|
const { Writable } = require('stream-browserify');
|
||||||
|
const { Buffer } = require('buffer');
|
||||||
|
|
||||||
class FsDriverRN extends FsDriverBase {
|
class FsDriverRN extends FsDriverBase {
|
||||||
appendFileSync() {
|
appendFileSync() {
|
||||||
@ -24,8 +26,25 @@ class FsDriverRN extends FsDriverBase {
|
|||||||
return await this.unlink(path);
|
return await this.unlink(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeBinaryFile() {
|
writeBinaryFile(path, content) {
|
||||||
throw new Error('Not implemented');
|
const buffer = Buffer.from(content);
|
||||||
|
return RNFetchBlob.fs.writeStream(path, 'base64').then(stream => {
|
||||||
|
const fileStream = new Writable({
|
||||||
|
write(chunk, encoding, callback) {
|
||||||
|
this.stream.write(chunk.toString('base64'));
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
final(callback) {
|
||||||
|
this.stream.close();
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// using options.construct is not implemented in readable-stream so lets
|
||||||
|
// pass the stream from RNFetchBlob to the Writable instance here
|
||||||
|
fileStream.stream = stream;
|
||||||
|
fileStream.write(buffer);
|
||||||
|
fileStream.end();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a format compatible with Node.js format
|
// Returns a format compatible with Node.js format
|
||||||
|
Reference in New Issue
Block a user