mobiletto-base
Advanced tools
Comparing version 1.0.12 to 1.0.13
38
index.js
@@ -233,3 +233,3 @@ const fs = require('fs') | ||
if (srcSize) { | ||
const destMeta = client.safeMetadata(destFullPath) | ||
const destMeta = await client.safeMetadata(destFullPath) | ||
if (destMeta && destMeta.size && destMeta.size && destMeta.size === srcSize) { | ||
@@ -244,18 +244,26 @@ logger.info(`mirror: dest object (${destFullPath}) has same size (${srcSize}) as src object ${sourcePath}, not copying`) | ||
const writer = fs.createWriteStream(tempPath, {fd, flags: 'wx'}) | ||
await source.read(obj.name, async (chunk) => { | ||
if (chunk) { writer.write(chunk) } | ||
}, () => { | ||
writer.close((err) => { | ||
if (err) { throw new MobilettoError(`mirror: error closing temp file: ${err}`) } | ||
logger.debug(`mirror: finished writing ${obj.name} to temp file ${tempPath}`) | ||
await new Promise((resolve, reject) => { | ||
source.read(obj.name, async (chunk) => { | ||
if (chunk) { writer.write(chunk) } | ||
}, () => { | ||
writer.close((err) => { | ||
if (err) { throw new MobilettoError(`mirror: error closing temp file: ${err}`) } | ||
logger.debug(`mirror: finished writing ${obj.name} to temp file ${tempPath}`) | ||
}) | ||
}).then(async () => { | ||
// read from temp file -> write to mirror | ||
const fd = fs.openSync(tempPath, 'r') | ||
const reader = fs.createReadStream(tempPath, {fd}) | ||
logger.debug(`mirror: writing temp file ${tempPath} to destination: ${destFullPath}`) | ||
await client.write(destFullPath, reader) | ||
logger.debug(`mirror: finished writing temp file ${tempPath} to destination: ${destFullPath}`) | ||
results.success++ | ||
resolve(destFullPath) | ||
}).catch((e) => { | ||
logger.warn(`mirror: error copying file: ${e}`) | ||
results.errors++ | ||
reject(e) | ||
}) | ||
}).then(async () => { | ||
// read from temp file -> write to mirror | ||
const fd = fs.openSync(tempPath, 'r') | ||
const reader = fs.createReadStream(tempPath, {fd}) | ||
logger.debug(`mirror: writing temp file ${tempPath} to destination: ${destFullPath}`) | ||
await client.write(destFullPath, reader) | ||
logger.debug(`mirror: finished writing temp file ${tempPath} to destination: ${destFullPath}`) | ||
}) | ||
results.success++ | ||
} catch (e) { | ||
@@ -262,0 +270,0 @@ logger.warn(`mirror: error copying file: ${e}`) |
{ | ||
"name": "mobiletto-base", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "A storage layer that presents a uniform interface to Amazon S3, Backblaze B2, local and other storage systems.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
58464
1076