1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop, Cli: Fixed issue with importing resources from ENEX files

This commit is contained in:
Laurent Cozic 2020-06-14 16:26:35 +00:00
parent 95d8ee65a5
commit 3733858145

View File

@ -38,13 +38,28 @@ function extractRecognitionObjId(recognitionXml) {
return r && r.length >= 2 ? r[1] : null;
}
async function decodeBase64File(sourceFile, destFile) {
async function decodeBase64File(sourceFilePath, destFilePath) {
return new Promise(function(resolve, reject) {
const sourceStream = fs.createReadStream(sourceFile);
const destStream = fs.createWriteStream(destFile);
// Note: we manually handle closing the file so that we can
// force flusing it before close. This is needed because
// "end" might be called before the file has been flushed
// to disk, thus resulting in the calling code to find a
// file with size 0.
const destFile = fs.openSync(destFilePath, 'w');
const sourceStream = fs.createReadStream(sourceFilePath);
const destStream = fs.createWriteStream(destFile, {
fd: destFile,
autoClose: false,
});
sourceStream.pipe(new Base64Decode()).pipe(destStream);
sourceStream.on('end', () => resolve());
sourceStream.on('end', () => {
fs.fdatasyncSync(destFile);
fs.closeSync(destFile);
resolve();
});
sourceStream.on('error', (error) => reject(error));
});
}