@xen-orchestra/fs 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_copyStreamToBuffer.js +0 -1
- package/dist/_copyStreamToBuffer.js.map +1 -1
- package/dist/_createBufferFromStream.js +0 -1
- package/dist/_createBufferFromStream.js.map +1 -1
- package/dist/_encryptor.js +76 -24
- package/dist/_encryptor.js.map +1 -1
- package/dist/_guessAwsRegion.js +0 -1
- package/dist/_guessAwsRegion.js.map +1 -1
- package/dist/_mount.js +3 -23
- package/dist/_mount.js.map +1 -1
- package/dist/abstract.js +42 -150
- package/dist/abstract.js.map +1 -1
- package/dist/checksum.js +0 -12
- package/dist/checksum.js.map +1 -1
- package/dist/index.js +19 -16
- package/dist/index.js.map +1 -1
- package/dist/local.js +31 -75
- package/dist/local.js.map +1 -1
- package/dist/nfs.js +0 -7
- package/dist/nfs.js.map +1 -1
- package/dist/path.js +1 -10
- package/dist/path.js.map +1 -1
- package/dist/s3.js +37 -105
- package/dist/s3.js.map +1 -1
- package/dist/smb.js +0 -8
- package/dist/smb.js.map +1 -1
- package/package.json +5 -5
package/dist/local.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local.js","names":["info","warn","createLogger","addSyncStackTrace","promise","stackContainer","Error","error","stack","LocalHandler","RemoteHandlerAbstract","constructor","remote","opts","_addSyncStackTrace","syncStackTraces","identity","_retriesOnEagain","delay","retries","retriesOnEagain","when","code","type","_getRealPath","_remote","path","_getFilePath","file","_closeFile","fd","fs","close","_copy","oldPath","newPath","copy","_createReadStream","options","stream","createReadStream","fromEvent","autoClose","_createWriteStream","createWriteStream","_getInfo","df","Object","keys","forEach","key","Number","isNaN","_getSize","stats","stat","size","_list","dir","readdir","_lock","acquire","lockfile","lock","bind","undefined","onCompromised","release","_mkdir","mode","mkdir","_openFile","flags","open","_read","buffer","position","needsClose","read","length","_readFile","filePath","retry","readFile","_rename","rename","_rmdir","rmdir","_sync","ensureDir","access","R_OK","W_OK","_truncate","len","truncate","_unlink","unlink","_writeFd","write","_writeFile","data","writeFile","flag"],"sources":["../src/local.js"],"sourcesContent":["import df from '@sindresorhus/df'\nimport fs from 'fs-extra'\nimport identity from 'lodash/identity.js'\nimport lockfile from 'proper-lockfile'\nimport { createLogger } from '@xen-orchestra/log'\nimport { fromEvent, retry } from 'promise-toolbox'\n\nimport RemoteHandlerAbstract from './abstract'\n\nconst { info, warn } = createLogger('xo:fs:local')\n\n// save current stack trace and add it to any rejected error\n//\n// This is especially useful when the resolution is separate from the initial\n// call, which is often the case with RPC libs.\n//\n// There is a perf impact and it should be avoided in production.\nasync function addSyncStackTrace(promise) {\n const stackContainer = new Error()\n try {\n return await promise\n } catch (error) {\n error.stack = stackContainer.stack\n throw error\n }\n}\n\nexport default class LocalHandler extends RemoteHandlerAbstract {\n constructor(remote, opts = {}) {\n super(remote)\n\n this._addSyncStackTrace = opts.syncStackTraces ?? true ? addSyncStackTrace : identity\n this._retriesOnEagain = {\n delay: 1e3,\n retries: 9,\n ...opts.retriesOnEagain,\n when: {\n code: 'EAGAIN',\n },\n }\n }\n get type() {\n return 'file'\n }\n\n _getRealPath() {\n return this._remote.path\n }\n\n _getFilePath(file) {\n return this._getRealPath() + file\n }\n\n async _closeFile(fd) {\n return this._addSyncStackTrace(fs.close(fd))\n }\n\n async _copy(oldPath, newPath) {\n return this._addSyncStackTrace(fs.copy(this._getFilePath(oldPath), this._getFilePath(newPath)))\n }\n\n async _createReadStream(file, options) {\n if (typeof file === 'string') {\n const stream = fs.createReadStream(this._getFilePath(file), options)\n await this._addSyncStackTrace(fromEvent(stream, 'open'))\n return stream\n }\n return fs.createReadStream('', {\n autoClose: false,\n ...options,\n fd: file.fd,\n })\n }\n\n async _createWriteStream(file, options) {\n if (typeof file === 'string') {\n const stream = fs.createWriteStream(this._getFilePath(file), options)\n await this._addSyncStackTrace(fromEvent(stream, 'open'))\n return stream\n }\n return fs.createWriteStream('', {\n autoClose: false,\n ...options,\n fd: file.fd,\n })\n }\n\n async _getInfo() {\n // df.file() resolves with an object with the following properties:\n // filesystem, type, size, used, available, capacity and mountpoint.\n // size, used, available and capacity may be `NaN` so we remove any `NaN`\n // value from the object.\n const info = await df.file(this._getFilePath('/'))\n Object.keys(info).forEach(key => {\n if (Number.isNaN(info[key])) {\n delete info[key]\n }\n })\n\n return info\n }\n\n async _getSize(file) {\n const stats = await this._addSyncStackTrace(fs.stat(this._getFilePath(typeof file === 'string' ? file : file.path)))\n return stats.size\n }\n\n async _list(dir) {\n return this._addSyncStackTrace(fs.readdir(this._getFilePath(dir)))\n }\n\n async _lock(path) {\n const acquire = lockfile.lock.bind(undefined, this._getFilePath(path), {\n async onCompromised(error) {\n warn('lock compromised', { error })\n try {\n release = await acquire()\n info('compromised lock was reacquired')\n } catch (error) {\n warn('compromised lock could not be reacquired', { error })\n }\n },\n })\n\n let release = await acquire()\n\n return async () => {\n try {\n await release()\n } catch (error) {\n warn('lock could not be released', { error })\n }\n }\n }\n\n _mkdir(dir, { mode }) {\n return this._addSyncStackTrace(fs.mkdir(this._getFilePath(dir), { mode }))\n }\n\n async _openFile(path, flags) {\n return this._addSyncStackTrace(fs.open(this._getFilePath(path), flags))\n }\n\n async _read(file, buffer, position) {\n const needsClose = typeof file === 'string'\n file = needsClose ? await this._addSyncStackTrace(fs.open(this._getFilePath(file), 'r')) : file.fd\n try {\n return await this._addSyncStackTrace(\n fs.read(file, buffer, 0, buffer.length, position === undefined ? null : position)\n )\n } finally {\n if (needsClose) {\n await this._addSyncStackTrace(fs.close(file))\n }\n }\n }\n\n async _readFile(file, options) {\n const filePath = this._getFilePath(file)\n return await this._addSyncStackTrace(retry(() => fs.readFile(filePath, options), this._retriesOnEagain))\n }\n\n async _rename(oldPath, newPath) {\n return this._addSyncStackTrace(fs.rename(this._getFilePath(oldPath), this._getFilePath(newPath)))\n }\n\n async _rmdir(dir) {\n return this._addSyncStackTrace(fs.rmdir(this._getFilePath(dir)))\n }\n\n async _sync() {\n const path = this._getRealPath('/')\n await this._addSyncStackTrace(fs.ensureDir(path))\n await this._addSyncStackTrace(fs.access(path, fs.R_OK | fs.W_OK))\n }\n\n _truncate(file, len) {\n return this._addSyncStackTrace(fs.truncate(this._getFilePath(file), len))\n }\n\n async _unlink(file) {\n const filePath = this._getFilePath(file)\n return await this._addSyncStackTrace(retry(() => fs.unlink(filePath), this._retriesOnEagain))\n }\n\n _writeFd(file, buffer, position) {\n return this._addSyncStackTrace(fs.write(file.fd, buffer, 0, buffer.length, position))\n }\n\n _writeFile(file, data, { flags }) {\n return this._addSyncStackTrace(fs.writeFile(this._getFilePath(file), data, { flag: flags }))\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AAEA,MAAM;EAAEA,IAAF;EAAQC;AAAR,IAAiB,IAAAC,iBAAA,EAAa,aAAb,CAAvB;;AAQA,eAAeC,iBAAf,CAAiCC,OAAjC,EAA0C;EACxC,MAAMC,cAAc,GAAG,IAAIC,KAAJ,EAAvB;;EACA,IAAI;IACF,OAAO,MAAMF,OAAb;EACD,CAFD,CAEE,OAAOG,KAAP,EAAc;IACdA,KAAK,CAACC,KAAN,GAAcH,cAAc,CAACG,KAA7B;IACA,MAAMD,KAAN;EACD;AACF;;AAEc,MAAME,YAAN,SAA2BC,iBAA3B,CAAiD;EAC9DC,WAAW,CAACC,MAAD,EAASC,IAAI,GAAG,EAAhB,EAAoB;IAC7B,MAAMD,MAAN;IAEA,KAAKE,kBAAL,GAA0BD,IAAI,CAACE,eAAL,IAAwB,IAAxB,GAA+BZ,iBAA/B,GAAmDa,iBAA7E;IACA,KAAKC,gBAAL,GAAwB;MACtBC,KAAK,EAAE,GADe;MAEtBC,OAAO,EAAE,CAFa;MAGtB,GAAGN,IAAI,CAACO,eAHc;MAItBC,IAAI,EAAE;QACJC,IAAI,EAAE;MADF;IAJgB,CAAxB;EAQD;;EACO,IAAJC,IAAI,G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AAKZ,kBAAL,CAAwBiB,gBAAA,CAAG2D,MAAH,CAAUhE,IAAV,EAAgBK,gBAAA,CAAG4D,IAAH,GAAU5D,gBAAA,CAAG6D,IAA7B,CAAxB,CAAN;EACD;;EAEDC,SAAS,CAACjE,IAAD,EAAOkE,GAAP,EAAY;IACnB,OAAO,KAAKhF,kBAAL,CAAwBiB,gBAAA,CAAGgE,QAAH,CAAY,KAAKpE,YAAL,CAAkBC,IAAlB,CAAZ,EAAqCkE,GAArC,CAAxB,CAAP;EACD;;EAEY,MAAPE,OAAO,CAACpE,IAAD,EAAO;IAClB,MAAMqD,QAAQ,GAAG,KAAKtD,YAAL,CAAkBC,IAAlB,CAAjB;;IACA,OAAO,MAAM,KAAKd,kBAAL,CAAwB,IAAAoE,qBAAA,EAAM,MAAMnD,gBAAA,CAAGkE,MAAH,CAAUhB,QAAV,CAAZ,EAAiC,KAAKhE,gBAAtC,CAAxB,CAAb;EACD;;EAEDiF,QAAQ,CAACtE,IAAD,EAAO+C,MAAP,EAAeC,QAAf,EAAyB;IAC/B,OAAO,KAAK9D,kBAAL,CAAwBiB,gBAAA,CAAGoE,KAAH,CAASvE,IAAI,CAACE,EAAd,EAAkB6C,MAAlB,EAA0B,CAA1B,EAA6BA,MAAM,CAACI,MAApC,EAA4CH,QAA5C,CAAxB,CAAP;EACD;;EAEDwB,UAAU,CAACxE,IAAD,EAAOyE,IAAP,EAAa;IAAE7B;EAAF,CAAb,EAAwB;IAChC,OAAO,KAAK1D,kBAAL,CAAwBiB,gBAAA,CAAGuE,SAAH,CAAa,KAAK3E,YAAL,CAAkBC,IAAlB,CAAb,EAAsCyE,IAAtC,EAA4C;MAAEE,IAAI,EAAE/B;IAAR,CAA5C,CAAxB,CAAP;EACD;;AApK6D"}
|
|
1
|
+
{"version":3,"file":"local.js","names":["info","warn","createLogger","addSyncStackTrace","fn","args","stackContainer","Error","apply","error","syncStack","stack","dontAddSyncStackTrace","LocalHandler","RemoteHandlerAbstract","constructor","remote","opts","_addSyncStackTrace","syncStackTraces","_retriesOnEagain","delay","retries","retriesOnEagain","when","code","type","_getRealPath","_remote","path","_getFilePath","file","_closeFile","fd","fs","close","_copy","oldPath","newPath","copy","_createReadStream","options","stream","createReadStream","fromEvent","autoClose","_createWriteStream","createWriteStream","_getInfo","df","Object","keys","forEach","key","Number","isNaN","_getSize","stats","stat","size","_list","dir","readdir","_lock","acquire","lockfile","lock","bind","undefined","onCompromised","release","_mkdir","mode","mkdir","_openFile","flags","open","_read","buffer","position","needsClose","read","length","_readFile","filePath","retry","readFile","_rename","rename","_rmdir","rmdir","_sync","ensureDir","access","R_OK","W_OK","_truncate","len","truncate","_unlink","unlink","_writeFd","write","_writeFile","data","writeFile","flag"],"sources":["../src/local.js"],"sourcesContent":["import df from '@sindresorhus/df'\nimport fs from 'fs-extra'\nimport lockfile from 'proper-lockfile'\nimport { createLogger } from '@xen-orchestra/log'\nimport { fromEvent, retry } from 'promise-toolbox'\n\nimport RemoteHandlerAbstract from './abstract'\n\nconst { info, warn } = createLogger('xo:fs:local')\n\n// save current stack trace and add it to any rejected error\n//\n// This is especially useful when the resolution is separate from the initial\n// call, which is often the case with RPC libs.\n//\n// There is a perf impact and it should be avoided in production.\nasync function addSyncStackTrace(fn, ...args) {\n const stackContainer = new Error()\n try {\n return await fn.apply(this, args)\n } catch (error) {\n error.syncStack = stackContainer.stack\n throw error\n }\n}\n\nfunction dontAddSyncStackTrace(fn, ...args) {\n return fn.apply(this, args)\n}\n\nexport default class LocalHandler extends RemoteHandlerAbstract {\n constructor(remote, opts = {}) {\n super(remote)\n\n this._addSyncStackTrace = opts.syncStackTraces ?? true ? addSyncStackTrace : dontAddSyncStackTrace\n this._retriesOnEagain = {\n delay: 1e3,\n retries: 9,\n ...opts.retriesOnEagain,\n when: {\n code: 'EAGAIN',\n },\n }\n }\n get type() {\n return 'file'\n }\n\n _getRealPath() {\n return this._remote.path\n }\n\n _getFilePath(file) {\n return this._getRealPath() + file\n }\n\n async _closeFile(fd) {\n return this._addSyncStackTrace(fs.close, fd)\n }\n\n async _copy(oldPath, newPath) {\n return this._addSyncStackTrace(fs.copy, this._getFilePath(oldPath), this._getFilePath(newPath))\n }\n\n async _createReadStream(file, options) {\n if (typeof file === 'string') {\n const stream = fs.createReadStream(this._getFilePath(file), options)\n await this._addSyncStackTrace(fromEvent, stream, 'open')\n return stream\n }\n return fs.createReadStream('', {\n autoClose: false,\n ...options,\n fd: file.fd,\n })\n }\n\n async _createWriteStream(file, options) {\n if (typeof file === 'string') {\n const stream = fs.createWriteStream(this._getFilePath(file), options)\n await this._addSyncStackTrace(fromEvent, stream, 'open')\n return stream\n }\n return fs.createWriteStream('', {\n autoClose: false,\n ...options,\n fd: file.fd,\n })\n }\n\n async _getInfo() {\n // df.file() resolves with an object with the following properties:\n // filesystem, type, size, used, available, capacity and mountpoint.\n // size, used, available and capacity may be `NaN` so we remove any `NaN`\n // value from the object.\n const info = await df.file(this._getFilePath('/'))\n Object.keys(info).forEach(key => {\n if (Number.isNaN(info[key])) {\n delete info[key]\n }\n })\n\n return info\n }\n\n async _getSize(file) {\n const stats = await this._addSyncStackTrace(fs.stat, this._getFilePath(typeof file === 'string' ? file : file.path))\n return stats.size\n }\n\n async _list(dir) {\n return this._addSyncStackTrace(fs.readdir, this._getFilePath(dir))\n }\n\n async _lock(path) {\n const acquire = lockfile.lock.bind(undefined, this._getFilePath(path), {\n async onCompromised(error) {\n warn('lock compromised', { error })\n try {\n release = await acquire()\n info('compromised lock was reacquired')\n } catch (error) {\n warn('compromised lock could not be reacquired', { error })\n }\n },\n })\n\n let release = await this._addSyncStackTrace(acquire)\n\n return async () => {\n try {\n await this._addSyncStackTrace(release)\n } catch (error) {\n warn('lock could not be released', { error })\n }\n }\n }\n\n _mkdir(dir, { mode }) {\n return this._addSyncStackTrace(fs.mkdir, this._getFilePath(dir), { mode })\n }\n\n async _openFile(path, flags) {\n return this._addSyncStackTrace(fs.open, this._getFilePath(path), flags)\n }\n\n async _read(file, buffer, position) {\n const needsClose = typeof file === 'string'\n file = needsClose ? await this._addSyncStackTrace(fs.open, this._getFilePath(file), 'r') : file.fd\n try {\n return await this._addSyncStackTrace(\n fs.read,\n file,\n buffer,\n 0,\n buffer.length,\n position === undefined ? null : position\n )\n } finally {\n if (needsClose) {\n await this._addSyncStackTrace(fs.close, file)\n }\n }\n }\n\n async _readFile(file, options) {\n const filePath = this._getFilePath(file)\n return await this._addSyncStackTrace(retry, () => fs.readFile(filePath, options), this._retriesOnEagain)\n }\n\n async _rename(oldPath, newPath) {\n return this._addSyncStackTrace(fs.rename, this._getFilePath(oldPath), this._getFilePath(newPath))\n }\n\n async _rmdir(dir) {\n return this._addSyncStackTrace(fs.rmdir, this._getFilePath(dir))\n }\n\n async _sync() {\n const path = this._getRealPath('/')\n await this._addSyncStackTrace(fs.ensureDir, path)\n await this._addSyncStackTrace(fs.access, path, fs.R_OK | fs.W_OK)\n }\n\n _truncate(file, len) {\n return this._addSyncStackTrace(fs.truncate, this._getFilePath(file), len)\n }\n\n async _unlink(file) {\n const filePath = this._getFilePath(file)\n return await this._addSyncStackTrace(retry, () => fs.unlink(filePath), this._retriesOnEagain)\n }\n\n _writeFd(file, buffer, position) {\n return this._addSyncStackTrace(fs.write, file.fd, buffer, 0, buffer.length, position)\n }\n\n _writeFile(file, data, { flags }) {\n return this._addSyncStackTrace(fs.writeFile, this._getFilePath(file), data, { flag: flags })\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA;AAA8C;AAE9C,MAAM;EAAEA,IAAI;EAAEC;AAAK,CAAC,GAAG,IAAAC,iBAAY,EAAC,aAAa,CAAC;;AAQlD,eAAeC,iBAAiB,CAACC,EAAE,EAAE,GAAGC,IAAI,EAAE;EAC5C,MAAMC,cAAc,GAAG,IAAIC,KAAK,EAAE;EAClC,IAAI;IACF,OAAO,MAAMH,EAAE,CAACI,KAAK,CAAC,IAAI,EAAEH,IAAI,CAAC;EACnC,CAAC,CAAC,OAAOI,KAAK,EA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7D,kBAAkB,CAACgB,gBAAE,CAACoE,KAAK,EAAEvE,IAAI,CAACE,EAAE,EAAE6C,MAAM,EAAE,CAAC,EAAEA,MAAM,CAACI,MAAM,EAAEH,QAAQ,CAAC;EACvF;EAEAwB,UAAU,CAACxE,IAAI,EAAEyE,IAAI,EAAE;IAAE7B;EAAM,CAAC,EAAE;IAChC,OAAO,IAAI,CAACzD,kBAAkB,CAACgB,gBAAE,CAACuE,SAAS,EAAE,IAAI,CAAC3E,YAAY,CAACC,IAAI,CAAC,EAAEyE,IAAI,EAAE;MAAEE,IAAI,EAAE/B;IAAM,CAAC,CAAC;EAC9F;AACF;AAAC"}
|
package/dist/nfs.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _xoRemoteParser = require("xo-remote-parser");
|
|
9
|
-
|
|
10
8
|
var _mount = _interopRequireDefault(require("./_mount"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
class NfsHandler extends _mount.default {
|
|
15
11
|
constructor(remote, opts) {
|
|
16
12
|
const {
|
|
@@ -23,12 +19,9 @@ class NfsHandler extends _mount.default {
|
|
|
23
19
|
device: `${host}${port !== undefined ? ':' + port : ''}:${path}`
|
|
24
20
|
});
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
get type() {
|
|
28
23
|
return 'nfs';
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
exports.default = NfsHandler;
|
|
34
27
|
//# sourceMappingURL=nfs.js.map
|
package/dist/nfs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nfs.js","names":["NfsHandler","MountHandler","constructor","remote","opts","host","port","path","parse","url","type","device","undefined"],"sources":["../src/nfs.js"],"sourcesContent":["import { parse } from 'xo-remote-parser'\n\nimport MountHandler from './_mount'\n\nexport default class NfsHandler extends MountHandler {\n constructor(remote, opts) {\n const { host, port, path } = parse(remote.url)\n super(remote, opts, {\n type: 'nfs',\n device: `${host}${port !== undefined ? ':' + port : ''}:${path}`,\n })\n }\n\n get type() {\n return 'nfs'\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"nfs.js","names":["NfsHandler","MountHandler","constructor","remote","opts","host","port","path","parse","url","type","device","undefined"],"sources":["../src/nfs.js"],"sourcesContent":["import { parse } from 'xo-remote-parser'\n\nimport MountHandler from './_mount'\n\nexport default class NfsHandler extends MountHandler {\n constructor(remote, opts) {\n const { host, port, path } = parse(remote.url)\n super(remote, opts, {\n type: 'nfs',\n device: `${host}${port !== undefined ? ':' + port : ''}:${path}`,\n })\n }\n\n get type() {\n return 'nfs'\n }\n}\n"],"mappings":";;;;;;AAAA;AAEA;AAAmC;AAEpB,MAAMA,UAAU,SAASC,cAAY,CAAC;EACnDC,WAAW,CAACC,MAAM,EAAEC,IAAI,EAAE;IACxB,MAAM;MAAEC,IAAI;MAAEC,IAAI;MAAEC;IAAK,CAAC,GAAG,IAAAC,qBAAK,EAACL,MAAM,CAACM,GAAG,CAAC;IAC9C,KAAK,CAACN,MAAM,EAAEC,IAAI,EAAE;MAClBM,IAAI,EAAE,KAAK;MACXC,MAAM,EAAG,GAAEN,IAAK,GAAEC,IAAI,KAAKM,SAAS,GAAG,GAAG,GAAGN,IAAI,GAAG,EAAG,IAAGC,IAAK;IACjE,CAAC,CAAC;EACJ;EAEA,IAAIG,IAAI,GAAG;IACT,OAAO,KAAK;EACd;AACF;AAAC"}
|
package/dist/path.js
CHANGED
|
@@ -5,11 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.resolveFromFile = exports.relativeFromFile = exports.normalize = exports.join = exports.dirname = exports.basename = void 0;
|
|
7
7
|
exports.split = split;
|
|
8
|
-
|
|
9
8
|
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
10
|
const {
|
|
14
11
|
basename,
|
|
15
12
|
dirname,
|
|
@@ -21,22 +18,16 @@ const {
|
|
|
21
18
|
exports.join = join;
|
|
22
19
|
exports.dirname = dirname;
|
|
23
20
|
exports.basename = basename;
|
|
24
|
-
|
|
25
21
|
const normalize = path => resolve('/', path);
|
|
26
|
-
|
|
27
22
|
exports.normalize = normalize;
|
|
28
|
-
|
|
29
23
|
function split(path) {
|
|
30
24
|
const parts = normalize(path).split(sep);
|
|
25
|
+
|
|
31
26
|
parts.shift();
|
|
32
27
|
return parts;
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
const relativeFromFile = (file, path) => relative(dirname(file), path);
|
|
36
|
-
|
|
37
30
|
exports.relativeFromFile = relativeFromFile;
|
|
38
|
-
|
|
39
31
|
const resolveFromFile = (file, path) => resolve('/', dirname(file), path).slice(1);
|
|
40
|
-
|
|
41
32
|
exports.resolveFromFile = resolveFromFile;
|
|
42
33
|
//# sourceMappingURL=path.js.map
|
package/dist/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","names":["basename","dirname","join","resolve","relative","sep","path","posix","normalize","split","parts","shift","relativeFromFile","file","resolveFromFile","slice"],"sources":["../src/path.js"],"sourcesContent":["import path from 'path'\n\nconst { basename, dirname, join, resolve, relative, sep } = path.posix\n\nexport { basename, dirname, join }\n\n// normalize the path:\n// - does not contains `.` or `..` (cannot escape root dir)\n// - always starts with `/`\n// - no trailing slash (expect for root)\n// - no duplicate slashes\nexport const normalize = path => resolve('/', path)\n\nexport function split(path) {\n const parts = normalize(path).split(sep)\n\n // remove first (empty) entry\n parts.shift()\n\n return parts\n}\n\nexport const relativeFromFile = (file, path) => relative(dirname(file), path)\nexport const resolveFromFile = (file, path) => resolve('/', dirname(file), path).slice(1)\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"path.js","names":["basename","dirname","join","resolve","relative","sep","path","posix","normalize","split","parts","shift","relativeFromFile","file","resolveFromFile","slice"],"sources":["../src/path.js"],"sourcesContent":["import path from 'path'\n\nconst { basename, dirname, join, resolve, relative, sep } = path.posix\n\nexport { basename, dirname, join }\n\n// normalize the path:\n// - does not contains `.` or `..` (cannot escape root dir)\n// - always starts with `/`\n// - no trailing slash (expect for root)\n// - no duplicate slashes\nexport const normalize = path => resolve('/', path)\n\nexport function split(path) {\n const parts = normalize(path).split(sep)\n\n // remove first (empty) entry\n parts.shift()\n\n return parts\n}\n\nexport const relativeFromFile = (file, path) => relative(dirname(file), path)\nexport const resolveFromFile = (file, path) => resolve('/', dirname(file), path).slice(1)\n"],"mappings":";;;;;;;AAAA;AAAuB;AAEvB,MAAM;EAAEA,QAAQ;EAAEC,OAAO;EAAEC,IAAI;EAAEC,OAAO;EAAEC,QAAQ;EAAEC;AAAI,CAAC,GAAGC,aAAI,CAACC,KAAK;AAAA;AAAA;AAAA;AAS/D,MAAMC,SAAS,GAAGF,IAAI,IAAIH,OAAO,CAAC,GAAG,EAAEG,IAAI,CAAC;AAAA;AAE5C,SAASG,KAAK,CAACH,IAAI,EAAE;EAC1B,MAAMI,KAAK,GAAGF,SAAS,CAACF,IAAI,CAAC,CAACG,KAAK,CAACJ,GAAG,CAAC;;EAGxCK,KAAK,CAACC,KAAK,EAAE;EAEb,OAAOD,KAAK;AACd;AAEO,MAAME,gBAAgB,GAAG,CAACC,IAAI,EAAEP,IAAI,KAAKF,QAAQ,CAACH,OAAO,CAACY,IAAI,CAAC,EAAEP,IAAI,CAAC;AAAA;AACtE,MAAMQ,eAAe,GAAG,CAACD,IAAI,EAAEP,IAAI,KAAKH,OAAO,CAAC,GAAG,EAAEF,OAAO,CAACY,IAAI,CAAC,EAAEP,IAAI,CAAC,CAACS,KAAK,CAAC,CAAC,CAAC;AAAA"}
|
package/dist/s3.js
CHANGED
|
@@ -4,47 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _clientS = require("@aws-sdk/client-s3");
|
|
9
|
-
|
|
10
8
|
var _libStorage = require("@aws-sdk/lib-storage");
|
|
11
|
-
|
|
12
9
|
var _nodeHttpHandler = require("@aws-sdk/node-http-handler");
|
|
13
|
-
|
|
14
10
|
var _middlewareApplyBodyChecksum = require("@aws-sdk/middleware-apply-body-checksum");
|
|
15
|
-
|
|
16
11
|
var _assert = _interopRequireDefault(require("assert"));
|
|
17
|
-
|
|
18
12
|
var _http = require("http");
|
|
19
|
-
|
|
20
13
|
var _https = require("https");
|
|
21
|
-
|
|
22
14
|
var _retry = _interopRequireDefault(require("promise-toolbox/retry"));
|
|
23
|
-
|
|
24
15
|
var _log = require("@xen-orchestra/log");
|
|
25
|
-
|
|
26
16
|
var _decorateWith = require("@vates/decorate-with");
|
|
27
|
-
|
|
28
17
|
var _stream = require("stream");
|
|
29
|
-
|
|
30
18
|
var _xoRemoteParser = require("xo-remote-parser");
|
|
31
|
-
|
|
32
19
|
var _copyStreamToBuffer = _interopRequireDefault(require("./_copyStreamToBuffer.js"));
|
|
33
|
-
|
|
34
20
|
var _createBufferFromStream = _interopRequireDefault(require("./_createBufferFromStream.js"));
|
|
35
|
-
|
|
36
21
|
var _guessAwsRegion = _interopRequireDefault(require("./_guessAwsRegion.js"));
|
|
37
|
-
|
|
38
22
|
var _abstract = _interopRequireDefault(require("./abstract"));
|
|
39
|
-
|
|
40
23
|
var _path = require("./path");
|
|
41
|
-
|
|
42
24
|
var _asyncEach = require("@vates/async-each");
|
|
43
|
-
|
|
44
25
|
var _dec, _class;
|
|
45
|
-
|
|
46
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
47
|
-
|
|
48
27
|
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
49
28
|
|
|
50
29
|
const MIN_PART_SIZE = 1024 * 1024 * 5;
|
|
@@ -52,6 +31,7 @@ const MAX_PART_SIZE = 1024 * 1024 * 1024 * 5;
|
|
|
52
31
|
const MAX_PARTS_COUNT = 10000;
|
|
53
32
|
const MAX_OBJECT_SIZE = 1024 * 1024 * 1024 * 1024 * 5;
|
|
54
33
|
const IDEAL_FRAGMENT_SIZE = Math.ceil(MAX_OBJECT_SIZE / MAX_PARTS_COUNT);
|
|
34
|
+
|
|
55
35
|
const {
|
|
56
36
|
warn
|
|
57
37
|
} = (0, _log.createLogger)('xo:fs:s3');
|
|
@@ -59,10 +39,8 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
59
39
|
delays: [100, 200, 500, 1000, 2000],
|
|
60
40
|
when: e => {
|
|
61
41
|
var _e$$metadata;
|
|
62
|
-
|
|
63
42
|
return ((_e$$metadata = e.$metadata) === null || _e$$metadata === void 0 ? void 0 : _e$$metadata.httpStatusCode) === 500;
|
|
64
43
|
},
|
|
65
|
-
|
|
66
44
|
onRetry(error) {
|
|
67
45
|
warn('retrying writing file', {
|
|
68
46
|
attemptNumber: this.attemptNumber,
|
|
@@ -71,7 +49,6 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
71
49
|
file: this.arguments[0]
|
|
72
50
|
});
|
|
73
51
|
}
|
|
74
|
-
|
|
75
52
|
}), (_class = class S3Handler extends _abstract.default {
|
|
76
53
|
constructor(remote, _opts) {
|
|
77
54
|
super(remote);
|
|
@@ -107,24 +84,19 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
107
84
|
});
|
|
108
85
|
|
|
109
86
|
this._s3.middlewareStack.use((0, _middlewareApplyBodyChecksum.getApplyMd5BodyChecksumPlugin)(this._s3.config));
|
|
110
|
-
|
|
111
87
|
const parts = (0, _path.split)(path);
|
|
112
88
|
this._bucket = parts.shift();
|
|
113
89
|
this._dir = (0, _path.join)(...parts);
|
|
114
90
|
}
|
|
115
|
-
|
|
116
91
|
get type() {
|
|
117
92
|
return 's3';
|
|
118
93
|
}
|
|
119
|
-
|
|
120
94
|
_makeCopySource(path) {
|
|
121
95
|
return (0, _path.join)(this._bucket, this._dir, path);
|
|
122
96
|
}
|
|
123
|
-
|
|
124
97
|
_makeKey(file) {
|
|
125
98
|
return (0, _path.join)(this._dir, file);
|
|
126
99
|
}
|
|
127
|
-
|
|
128
100
|
_makePrefix(dir) {
|
|
129
101
|
const prefix = (0, _path.join)(this._dir, dir, '/');
|
|
130
102
|
|
|
@@ -132,29 +104,25 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
132
104
|
return prefix;
|
|
133
105
|
}
|
|
134
106
|
}
|
|
135
|
-
|
|
136
107
|
_createParams(file) {
|
|
137
108
|
return {
|
|
138
109
|
Bucket: this._bucket,
|
|
139
110
|
Key: this._makeKey(file)
|
|
140
111
|
};
|
|
141
112
|
}
|
|
142
|
-
|
|
143
113
|
async _multipartCopy(oldPath, newPath) {
|
|
144
114
|
const size = await this._getSize(oldPath);
|
|
145
|
-
|
|
146
115
|
const CopySource = this._makeCopySource(oldPath);
|
|
147
|
-
|
|
148
|
-
|
|
116
|
+
const multipartParams = await this._s3.send(new _clientS.CreateMultipartUploadCommand({
|
|
117
|
+
...this._createParams(newPath)
|
|
149
118
|
}));
|
|
150
|
-
|
|
151
119
|
try {
|
|
152
120
|
const parts = [];
|
|
153
121
|
let start = 0;
|
|
154
|
-
|
|
155
122
|
while (start < size) {
|
|
156
123
|
const partNumber = parts.length + 1;
|
|
157
|
-
const upload = await this._s3.send(new _clientS.UploadPartCopyCommand({
|
|
124
|
+
const upload = await this._s3.send(new _clientS.UploadPartCopyCommand({
|
|
125
|
+
...multipartParams,
|
|
158
126
|
CopySource,
|
|
159
127
|
CopySourceRange: `bytes=${start}-${Math.min(start + MAX_PART_SIZE, size) - 1}`,
|
|
160
128
|
PartNumber: partNumber
|
|
@@ -165,8 +133,8 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
165
133
|
});
|
|
166
134
|
start += MAX_PART_SIZE;
|
|
167
135
|
}
|
|
168
|
-
|
|
169
|
-
|
|
136
|
+
await this._s3.send(new _clientS.CompleteMultipartUploadCommand({
|
|
137
|
+
...multipartParams,
|
|
170
138
|
MultipartUpload: {
|
|
171
139
|
Parts: parts
|
|
172
140
|
}
|
|
@@ -176,26 +144,29 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
176
144
|
throw e;
|
|
177
145
|
}
|
|
178
146
|
}
|
|
179
|
-
|
|
180
147
|
async _copy(oldPath, newPath) {
|
|
181
148
|
const CopySource = this._makeCopySource(oldPath);
|
|
182
|
-
|
|
183
149
|
try {
|
|
184
|
-
await this._s3.send(new _clientS.CopyObjectCommand({
|
|
150
|
+
await this._s3.send(new _clientS.CopyObjectCommand({
|
|
151
|
+
...this._createParams(newPath),
|
|
185
152
|
CopySource
|
|
186
153
|
}));
|
|
187
154
|
} catch (e) {
|
|
188
155
|
if (e.name === 'EntityTooLarge') {
|
|
189
156
|
return this._multipartCopy(oldPath, newPath);
|
|
190
157
|
}
|
|
191
|
-
|
|
158
|
+
if (e.name === 'NoSuchKey') {
|
|
159
|
+
const error = new Error(`ENOENT: no such file or directory '${oldPath}'`);
|
|
160
|
+
error.cause = e;
|
|
161
|
+
error.code = 'ENOENT';
|
|
162
|
+
error.path = oldPath;
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
192
165
|
throw e;
|
|
193
166
|
}
|
|
194
167
|
}
|
|
195
|
-
|
|
196
168
|
async _isNotEmptyDir(path) {
|
|
197
169
|
var _result$Contents;
|
|
198
|
-
|
|
199
170
|
const result = await this._s3.send(new _clientS.ListObjectsV2Command({
|
|
200
171
|
Bucket: this._bucket,
|
|
201
172
|
MaxKeys: 1,
|
|
@@ -203,7 +174,6 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
203
174
|
}));
|
|
204
175
|
return ((_result$Contents = result.Contents) === null || _result$Contents === void 0 ? void 0 : _result$Contents.length) > 0;
|
|
205
176
|
}
|
|
206
|
-
|
|
207
177
|
async _isFile(path) {
|
|
208
178
|
try {
|
|
209
179
|
await this._s3.send(new _clientS.HeadObjectCommand(this._createParams(path)));
|
|
@@ -212,11 +182,9 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
212
182
|
if (error.name === 'NotFound') {
|
|
213
183
|
return false;
|
|
214
184
|
}
|
|
215
|
-
|
|
216
185
|
throw error;
|
|
217
186
|
}
|
|
218
187
|
}
|
|
219
|
-
|
|
220
188
|
async _outputStream(path, input, {
|
|
221
189
|
validator
|
|
222
190
|
}) {
|
|
@@ -226,12 +194,12 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
226
194
|
client: this._s3,
|
|
227
195
|
queueSize: 1,
|
|
228
196
|
partSize: IDEAL_FRAGMENT_SIZE,
|
|
229
|
-
params: {
|
|
197
|
+
params: {
|
|
198
|
+
...this._createParams(path),
|
|
230
199
|
Body
|
|
231
200
|
}
|
|
232
201
|
});
|
|
233
202
|
await upload.done();
|
|
234
|
-
|
|
235
203
|
if (validator !== undefined) {
|
|
236
204
|
try {
|
|
237
205
|
await validator.call(this, path);
|
|
@@ -243,11 +211,11 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
243
211
|
}
|
|
244
212
|
|
|
245
213
|
async _writeFile(file, data, options) {
|
|
246
|
-
return this._s3.send(new _clientS.PutObjectCommand({
|
|
214
|
+
return this._s3.send(new _clientS.PutObjectCommand({
|
|
215
|
+
...this._createParams(file),
|
|
247
216
|
Body: data
|
|
248
217
|
}));
|
|
249
218
|
}
|
|
250
|
-
|
|
251
219
|
async _createReadStream(path, options) {
|
|
252
220
|
try {
|
|
253
221
|
return (await this._s3.send(new _clientS.GetObjectCommand(this._createParams(path)))).Body;
|
|
@@ -258,14 +226,11 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
258
226
|
error.path = path;
|
|
259
227
|
throw error;
|
|
260
228
|
}
|
|
261
|
-
|
|
262
229
|
throw e;
|
|
263
230
|
}
|
|
264
231
|
}
|
|
265
|
-
|
|
266
232
|
async _unlink(path) {
|
|
267
233
|
await this._s3.send(new _clientS.DeleteObjectCommand(this._createParams(path)));
|
|
268
|
-
|
|
269
234
|
if (await this._isNotEmptyDir(path)) {
|
|
270
235
|
const error = new Error(`EISDIR: illegal operation on a directory, unlink '${path}'`);
|
|
271
236
|
error.code = 'EISDIR';
|
|
@@ -273,13 +238,10 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
273
238
|
throw error;
|
|
274
239
|
}
|
|
275
240
|
}
|
|
276
|
-
|
|
277
241
|
async _list(dir) {
|
|
278
242
|
let NextContinuationToken;
|
|
279
243
|
const uniq = new Set();
|
|
280
|
-
|
|
281
244
|
const Prefix = this._makePrefix(dir);
|
|
282
|
-
|
|
283
245
|
do {
|
|
284
246
|
const result = await this._s3.send(new _clientS.ListObjectsV2Command({
|
|
285
247
|
Bucket: this._bucket,
|
|
@@ -287,7 +249,6 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
287
249
|
Delimiter: '/',
|
|
288
250
|
ContinuationToken: NextContinuationToken
|
|
289
251
|
}));
|
|
290
|
-
|
|
291
252
|
if (result.IsTruncated) {
|
|
292
253
|
warn(`need pagination to browse the directory ${dir} completely`);
|
|
293
254
|
NextContinuationToken = result.NextContinuationToken;
|
|
@@ -303,10 +264,8 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
303
264
|
uniq.add((0, _path.basename)(entry.Key));
|
|
304
265
|
}
|
|
305
266
|
} while (NextContinuationToken !== undefined);
|
|
306
|
-
|
|
307
267
|
return [...uniq];
|
|
308
268
|
}
|
|
309
|
-
|
|
310
269
|
async _mkdir(path) {
|
|
311
270
|
if (await this._isFile(path)) {
|
|
312
271
|
const error = new Error(`ENOTDIR: file already exists, mkdir '${path}'`);
|
|
@@ -320,25 +279,19 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
320
279
|
await this.copy(oldPath, newPath);
|
|
321
280
|
await this._s3.send(new _clientS.DeleteObjectCommand(this._createParams(oldPath)));
|
|
322
281
|
}
|
|
323
|
-
|
|
324
282
|
async _getSize(file) {
|
|
325
283
|
if (typeof file !== 'string') {
|
|
326
284
|
file = file.fd;
|
|
327
285
|
}
|
|
328
|
-
|
|
329
286
|
const result = await this._s3.send(new _clientS.HeadObjectCommand(this._createParams(file)));
|
|
330
287
|
return +result.ContentLength;
|
|
331
288
|
}
|
|
332
|
-
|
|
333
289
|
async _read(file, buffer, position = 0) {
|
|
334
290
|
if (typeof file !== 'string') {
|
|
335
291
|
file = file.fd;
|
|
336
292
|
}
|
|
337
|
-
|
|
338
293
|
const params = this._createParams(file);
|
|
339
|
-
|
|
340
294
|
params.Range = `bytes=${position}-${position + buffer.length - 1}`;
|
|
341
|
-
|
|
342
295
|
try {
|
|
343
296
|
const result = await this._s3.send(new _clientS.GetObjectCommand(params));
|
|
344
297
|
const bytesRead = await (0, _copyStreamToBuffer.default)(result.Body, buffer);
|
|
@@ -355,11 +308,9 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
355
308
|
throw error;
|
|
356
309
|
}
|
|
357
310
|
}
|
|
358
|
-
|
|
359
311
|
throw e;
|
|
360
312
|
}
|
|
361
313
|
}
|
|
362
|
-
|
|
363
314
|
async _rmdir(path) {
|
|
364
315
|
if (await this._isNotEmptyDir(path)) {
|
|
365
316
|
const error = new Error(`ENOTEMPTY: directory not empty, rmdir '${path}`);
|
|
@@ -367,13 +318,12 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
367
318
|
error.path = path;
|
|
368
319
|
throw error;
|
|
369
320
|
}
|
|
321
|
+
|
|
370
322
|
}
|
|
371
323
|
|
|
372
324
|
async _rmtree(path) {
|
|
373
325
|
let NextContinuationToken;
|
|
374
|
-
|
|
375
326
|
const Prefix = this._makePrefix(path);
|
|
376
|
-
|
|
377
327
|
do {
|
|
378
328
|
const result = await this._s3.send(new _clientS.ListObjectsV2Command({
|
|
379
329
|
Bucket: this._bucket,
|
|
@@ -393,16 +343,12 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
393
343
|
});
|
|
394
344
|
} while (NextContinuationToken !== undefined);
|
|
395
345
|
}
|
|
396
|
-
|
|
397
346
|
async _write(file, buffer, position) {
|
|
398
347
|
if (typeof file !== 'string') {
|
|
399
348
|
file = file.fd;
|
|
400
349
|
}
|
|
401
|
-
|
|
402
350
|
const uploadParams = this._createParams(file);
|
|
403
|
-
|
|
404
351
|
let fileSize;
|
|
405
|
-
|
|
406
352
|
try {
|
|
407
353
|
fileSize = +(await this._s3.send(new _clientS.HeadObjectCommand(uploadParams))).ContentLength;
|
|
408
354
|
} catch (e) {
|
|
@@ -412,19 +358,17 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
412
358
|
throw e;
|
|
413
359
|
}
|
|
414
360
|
}
|
|
415
|
-
|
|
416
361
|
if (fileSize < MIN_PART_SIZE) {
|
|
417
362
|
const resultBuffer = Buffer.alloc(Math.max(fileSize, position + buffer.length));
|
|
418
|
-
|
|
419
363
|
if (fileSize !== 0) {
|
|
420
364
|
const result = await this._s3.send(new _clientS.GetObjectCommand(uploadParams));
|
|
421
365
|
await (0, _copyStreamToBuffer.default)(result.Body, resultBuffer);
|
|
422
366
|
} else {
|
|
423
367
|
Buffer.alloc(0).copy(resultBuffer);
|
|
424
368
|
}
|
|
425
|
-
|
|
426
369
|
buffer.copy(resultBuffer, position);
|
|
427
|
-
await this._s3.send(new _clientS.PutObjectCommand({
|
|
370
|
+
await this._s3.send(new _clientS.PutObjectCommand({
|
|
371
|
+
...uploadParams,
|
|
428
372
|
Body: resultBuffer
|
|
429
373
|
}));
|
|
430
374
|
return {
|
|
@@ -433,10 +377,10 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
433
377
|
};
|
|
434
378
|
} else {
|
|
435
379
|
const multipartParams = await this._s3.send(new _clientS.CreateMultipartUploadCommand(uploadParams));
|
|
436
|
-
const copyMultipartParams = {
|
|
380
|
+
const copyMultipartParams = {
|
|
381
|
+
...multipartParams,
|
|
437
382
|
CopySource: this._makeCopySource(file)
|
|
438
383
|
};
|
|
439
|
-
|
|
440
384
|
try {
|
|
441
385
|
const parts = [];
|
|
442
386
|
const prefixSize = position;
|
|
@@ -450,19 +394,16 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
450
394
|
let fragmentsCount = Math.floor(prefixSize / MAX_PART_SIZE);
|
|
451
395
|
const prefixFragmentSize = MAX_PART_SIZE;
|
|
452
396
|
let prefixLastFragmentSize = prefixSize - prefixFragmentSize * fragmentsCount;
|
|
453
|
-
|
|
454
397
|
if (prefixLastFragmentSize >= MIN_PART_SIZE) {
|
|
455
398
|
fragmentsCount++;
|
|
456
399
|
prefixLastFragmentSize = 0;
|
|
457
400
|
}
|
|
458
|
-
|
|
459
401
|
for (let i = 0; i < fragmentsCount; i++) {
|
|
460
402
|
const fragmentEnd = Math.min(prefixPosition + prefixFragmentSize, prefixSize);
|
|
461
|
-
|
|
462
403
|
_assert.default.strictEqual(fragmentEnd - prefixPosition <= MAX_PART_SIZE, true);
|
|
463
|
-
|
|
464
404
|
const range = `bytes=${prefixPosition}-${fragmentEnd - 1}`;
|
|
465
|
-
const copyPrefixParams = {
|
|
405
|
+
const copyPrefixParams = {
|
|
406
|
+
...copyMultipartParams,
|
|
466
407
|
PartNumber: partNumber++,
|
|
467
408
|
CopySourceRange: range
|
|
468
409
|
};
|
|
@@ -473,24 +414,21 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
473
414
|
});
|
|
474
415
|
prefixPosition += prefixFragmentSize;
|
|
475
416
|
}
|
|
476
|
-
|
|
477
417
|
if (prefixLastFragmentSize) {
|
|
478
|
-
const downloadParams = {
|
|
418
|
+
const downloadParams = {
|
|
419
|
+
...uploadParams,
|
|
479
420
|
Range: `bytes=${prefixPosition}-${prefixSize - 1}`
|
|
480
421
|
};
|
|
481
422
|
let prefixBuffer;
|
|
482
|
-
|
|
483
423
|
if (prefixSize > 0) {
|
|
484
424
|
const result = await this._s3.send(new _clientS.GetObjectCommand(downloadParams));
|
|
485
425
|
prefixBuffer = await (0, _createBufferFromStream.default)(result.Body);
|
|
486
426
|
} else {
|
|
487
427
|
prefixBuffer = Buffer.alloc(0);
|
|
488
428
|
}
|
|
489
|
-
|
|
490
429
|
editBuffer = Buffer.concat([prefixBuffer, buffer]);
|
|
491
430
|
editBufferOffset -= prefixLastFragmentSize;
|
|
492
431
|
}
|
|
493
|
-
|
|
494
432
|
if (hasSuffix && editBuffer.length < MIN_PART_SIZE) {
|
|
495
433
|
const complementSize = Math.min(MIN_PART_SIZE - editBuffer.length, suffixSize);
|
|
496
434
|
const complementOffset = editBufferOffset + editBuffer.length;
|
|
@@ -498,15 +436,16 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
498
436
|
suffixSize -= complementSize;
|
|
499
437
|
hasSuffix = suffixSize > 0;
|
|
500
438
|
const prefixRange = `bytes=${complementOffset}-${complementOffset + complementSize - 1}`;
|
|
501
|
-
const downloadParams = {
|
|
439
|
+
const downloadParams = {
|
|
440
|
+
...uploadParams,
|
|
502
441
|
Range: prefixRange
|
|
503
442
|
};
|
|
504
443
|
const result = await this._s3.send(new _clientS.GetObjectCommand(downloadParams));
|
|
505
444
|
const complementBuffer = await (0, _createBufferFromStream.default)(result.Body);
|
|
506
445
|
editBuffer = Buffer.concat([editBuffer, complementBuffer]);
|
|
507
446
|
}
|
|
508
|
-
|
|
509
|
-
|
|
447
|
+
const editParams = {
|
|
448
|
+
...multipartParams,
|
|
510
449
|
Body: editBuffer,
|
|
511
450
|
PartNumber: partNumber++
|
|
512
451
|
};
|
|
@@ -515,18 +454,15 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
515
454
|
ETag: editPart.ETag,
|
|
516
455
|
PartNumber: editParams.PartNumber
|
|
517
456
|
});
|
|
518
|
-
|
|
519
457
|
if (hasSuffix) {
|
|
520
458
|
const suffixFragments = Math.ceil(suffixSize / MAX_PART_SIZE);
|
|
521
459
|
let suffixFragmentOffset = suffixOffset;
|
|
522
|
-
|
|
523
460
|
for (let i = 0; i < suffixFragments; i++) {
|
|
524
461
|
const fragmentEnd = suffixFragmentOffset + MAX_PART_SIZE;
|
|
525
|
-
|
|
526
462
|
_assert.default.strictEqual(Math.min(fileSize, fragmentEnd) - suffixFragmentOffset <= MAX_PART_SIZE, true);
|
|
527
|
-
|
|
528
463
|
const suffixRange = `bytes=${suffixFragmentOffset}-${Math.min(fileSize, fragmentEnd) - 1}`;
|
|
529
|
-
const copySuffixParams = {
|
|
464
|
+
const copySuffixParams = {
|
|
465
|
+
...copyMultipartParams,
|
|
530
466
|
PartNumber: partNumber++,
|
|
531
467
|
CopySourceRange: suffixRange
|
|
532
468
|
};
|
|
@@ -538,8 +474,8 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
538
474
|
suffixFragmentOffset = fragmentEnd;
|
|
539
475
|
}
|
|
540
476
|
}
|
|
541
|
-
|
|
542
|
-
|
|
477
|
+
await this._s3.send(new _clientS.CompleteMultipartUploadCommand({
|
|
478
|
+
...multipartParams,
|
|
543
479
|
MultipartUpload: {
|
|
544
480
|
Parts: parts
|
|
545
481
|
}
|
|
@@ -550,17 +486,13 @@ let S3Handler = (_dec = (0, _decorateWith.decorateWith)(_retry.default.wrap, {
|
|
|
550
486
|
}
|
|
551
487
|
}
|
|
552
488
|
}
|
|
553
|
-
|
|
554
489
|
async _openFile(path, flags) {
|
|
555
490
|
return path;
|
|
556
491
|
}
|
|
557
|
-
|
|
558
492
|
async _closeFile(fd) {}
|
|
559
|
-
|
|
560
493
|
useVhdDirectory() {
|
|
561
494
|
return true;
|
|
562
495
|
}
|
|
563
|
-
|
|
564
496
|
}, (_applyDecoratedDescriptor(_class.prototype, "_writeFile", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "_writeFile"), _class.prototype)), _class));
|
|
565
497
|
exports.default = S3Handler;
|
|
566
498
|
//# sourceMappingURL=s3.js.map
|