@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.
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = copyStreamToBuffer;
7
-
8
7
  function copyStreamToBuffer(inputStream, destinationBuffer) {
9
8
  return new Promise((resolve, reject) => {
10
9
  let index = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"_copyStreamToBuffer.js","names":["copyStreamToBuffer","inputStream","destinationBuffer","Promise","resolve","reject","index","on","chunk","copy","length","err"],"sources":["../src/_copyStreamToBuffer.js"],"sourcesContent":["/**\n * @param {Readable} inputStream\n * @param {Buffer} destinationBuffer\n * @returns {Promise<int>} Buffer length\n * @private\n */\nexport default function copyStreamToBuffer(inputStream, destinationBuffer) {\n return new Promise((resolve, reject) => {\n let index = 0\n\n inputStream.on('data', chunk => {\n chunk.copy(destinationBuffer, index)\n index += chunk.length\n })\n inputStream.on('end', () => resolve(index))\n inputStream.on('error', err => reject(err))\n })\n}\n"],"mappings":";;;;;;;AAMe,SAASA,kBAAT,CAA4BC,WAA5B,EAAyCC,iBAAzC,EAA4D;EACzE,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;IACtC,IAAIC,KAAK,GAAG,CAAZ;IAEAL,WAAW,CAACM,EAAZ,CAAe,MAAf,EAAuBC,KAAK,IAAI;MAC9BA,KAAK,CAACC,IAAN,CAAWP,iBAAX,EAA8BI,KAA9B;MACAA,KAAK,IAAIE,KAAK,CAACE,MAAf;IACD,CAHD;IAIAT,WAAW,CAACM,EAAZ,CAAe,KAAf,EAAsB,MAAMH,OAAO,CAACE,KAAD,CAAnC;IACAL,WAAW,CAACM,EAAZ,CAAe,OAAf,EAAwBI,GAAG,IAAIN,MAAM,CAACM,GAAD,CAArC;EACD,CATM,CAAP;AAUD"}
1
+ {"version":3,"file":"_copyStreamToBuffer.js","names":["copyStreamToBuffer","inputStream","destinationBuffer","Promise","resolve","reject","index","on","chunk","copy","length","err"],"sources":["../src/_copyStreamToBuffer.js"],"sourcesContent":["/**\n * @param {Readable} inputStream\n * @param {Buffer} destinationBuffer\n * @returns {Promise<int>} Buffer length\n * @private\n */\nexport default function copyStreamToBuffer(inputStream, destinationBuffer) {\n return new Promise((resolve, reject) => {\n let index = 0\n\n inputStream.on('data', chunk => {\n chunk.copy(destinationBuffer, index)\n index += chunk.length\n })\n inputStream.on('end', () => resolve(index))\n inputStream.on('error', err => reject(err))\n })\n}\n"],"mappings":";;;;;;AAMe,SAASA,kBAAkB,CAACC,WAAW,EAAEC,iBAAiB,EAAE;EACzE,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACtC,IAAIC,KAAK,GAAG,CAAC;IAEbL,WAAW,CAACM,EAAE,CAAC,MAAM,EAAEC,KAAK,IAAI;MAC9BA,KAAK,CAACC,IAAI,CAACP,iBAAiB,EAAEI,KAAK,CAAC;MACpCA,KAAK,IAAIE,KAAK,CAACE,MAAM;IACvB,CAAC,CAAC;IACFT,WAAW,CAACM,EAAE,CAAC,KAAK,EAAE,MAAMH,OAAO,CAACE,KAAK,CAAC,CAAC;IAC3CL,WAAW,CAACM,EAAE,CAAC,OAAO,EAAEI,GAAG,IAAIN,MAAM,CAACM,GAAG,CAAC,CAAC;EAC7C,CAAC,CAAC;AACJ"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = createBufferFromStream;
7
-
8
7
  function createBufferFromStream(stream) {
9
8
  return new Promise((resolve, reject) => {
10
9
  const chunks = [];
@@ -1 +1 @@
1
- {"version":3,"file":"_createBufferFromStream.js","names":["createBufferFromStream","stream","Promise","resolve","reject","chunks","on","chunk","push","Buffer","concat","error"],"sources":["../src/_createBufferFromStream.js"],"sourcesContent":["/**\n * @param {Readable} stream\n * @returns {Promise<Buffer>}\n * @private\n */\nexport default function createBufferFromStream(stream) {\n return new Promise((resolve, reject) => {\n const chunks = []\n stream.on('data', chunk => chunks.push(chunk))\n stream.on('end', () => resolve(Buffer.concat(chunks)))\n stream.on('error', error => reject(error))\n })\n}\n"],"mappings":";;;;;;;AAKe,SAASA,sBAAT,CAAgCC,MAAhC,EAAwC;EACrD,OAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;IACtC,MAAMC,MAAM,GAAG,EAAf;IACAJ,MAAM,CAACK,EAAP,CAAU,MAAV,EAAkBC,KAAK,IAAIF,MAAM,CAACG,IAAP,CAAYD,KAAZ,CAA3B;IACAN,MAAM,CAACK,EAAP,CAAU,KAAV,EAAiB,MAAMH,OAAO,CAACM,MAAM,CAACC,MAAP,CAAcL,MAAd,CAAD,CAA9B;IACAJ,MAAM,CAACK,EAAP,CAAU,OAAV,EAAmBK,KAAK,IAAIP,MAAM,CAACO,KAAD,CAAlC;EACD,CALM,CAAP;AAMD"}
1
+ {"version":3,"file":"_createBufferFromStream.js","names":["createBufferFromStream","stream","Promise","resolve","reject","chunks","on","chunk","push","Buffer","concat","error"],"sources":["../src/_createBufferFromStream.js"],"sourcesContent":["/**\n * @param {Readable} stream\n * @returns {Promise<Buffer>}\n * @private\n */\nexport default function createBufferFromStream(stream) {\n return new Promise((resolve, reject) => {\n const chunks = []\n stream.on('data', chunk => chunks.push(chunk))\n stream.on('end', () => resolve(Buffer.concat(chunks)))\n stream.on('error', error => reject(error))\n })\n}\n"],"mappings":";;;;;;AAKe,SAASA,sBAAsB,CAACC,MAAM,EAAE;EACrD,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACtC,MAAMC,MAAM,GAAG,EAAE;IACjBJ,MAAM,CAACK,EAAE,CAAC,MAAM,EAAEC,KAAK,IAAIF,MAAM,CAACG,IAAI,CAACD,KAAK,CAAC,CAAC;IAC9CN,MAAM,CAACK,EAAE,CAAC,KAAK,EAAE,MAAMH,OAAO,CAACM,MAAM,CAACC,MAAM,CAACL,MAAM,CAAC,CAAC,CAAC;IACtDJ,MAAM,CAACK,EAAE,CAAC,OAAO,EAAEK,KAAK,IAAIP,MAAM,CAACO,KAAK,CAAC,CAAC;EAC5C,CAAC,CAAC;AACJ"}
@@ -1,14 +1,25 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UNENCRYPTED_ALGORITHM = exports.DEFAULT_ENCRYPTION_ALGORITHM = void 0;
7
+ exports.isLegacyEncryptionAlgorithm = isLegacyEncryptionAlgorithm;
8
+ const {
9
+ pipeline
10
+ } = require('node:stream');
3
11
  const {
4
12
  readChunk
5
13
  } = require('@vates/read-chunk');
6
-
7
14
  const crypto = require('crypto');
8
-
9
- const pumpify = require('pumpify');
10
-
11
- function getEncryptor(key) {
15
+ const DEFAULT_ENCRYPTION_ALGORITHM = 'aes-256-gcm';
16
+ exports.DEFAULT_ENCRYPTION_ALGORITHM = DEFAULT_ENCRYPTION_ALGORITHM;
17
+ const UNENCRYPTED_ALGORITHM = 'none';
18
+ exports.UNENCRYPTED_ALGORITHM = UNENCRYPTED_ALGORITHM;
19
+ function isLegacyEncryptionAlgorithm(algorithm) {
20
+ return algorithm !== UNENCRYPTED_ALGORITHM && algorithm !== DEFAULT_ENCRYPTION_ALGORITHM;
21
+ }
22
+ function getEncryptor(algorithm = DEFAULT_ENCRYPTION_ALGORITHM, key) {
12
23
  if (key === undefined) {
13
24
  return {
14
25
  id: 'NULL_ENCRYPTOR',
@@ -21,39 +32,81 @@ function getEncryptor(key) {
21
32
  decryptStream: stream => stream
22
33
  };
23
34
  }
24
-
25
- const algorithm = 'aes-256-cbc';
26
- const ivLength = 16;
27
-
35
+ const info = crypto.getCipherInfo(algorithm, {
36
+ keyLength: key.length
37
+ });
38
+ if (info === undefined) {
39
+ const error = new Error(`Either the algorithm ${algorithm} is not available, or the key length ${key.length} is incorrect. Supported algorithm are ${crypto.getCiphers()}`);
40
+ error.code = 'BAD_ALGORITHM';
41
+ throw error;
42
+ }
43
+ const {
44
+ ivLength,
45
+ mode
46
+ } = info;
47
+ const authTagLength = ['gcm', 'ccm', 'ocb'].includes(mode) ? 16 : 0;
28
48
  function encryptStream(input) {
29
- const iv = crypto.randomBytes(ivLength);
30
- const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv);
31
- const encrypted = pumpify(input, cipher);
32
- encrypted.unshift(iv);
33
- return encrypted;
49
+ return pipeline(input, async function* (source) {
50
+ const iv = crypto.randomBytes(ivLength);
51
+ const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv);
52
+ yield iv;
53
+ for await (const data of source) {
54
+ yield cipher.update(data);
55
+ }
56
+ yield cipher.final();
57
+ if (authTagLength > 0) {
58
+ yield cipher.getAuthTag();
59
+ }
60
+ }, () => {});
34
61
  }
62
+ function decryptStream(encryptedStream) {
63
+ return pipeline(encryptedStream, async function* (source) {
35
64
 
36
- async function decryptStream(encryptedStream) {
37
- const iv = await readChunk(encryptedStream, ivLength);
38
- const cipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv);
39
- return pumpify(encryptedStream, cipher);
65
+ const iv = await readChunk(source, ivLength);
66
+ const cipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv);
67
+ let authTag = Buffer.alloc(0);
68
+ for await (const data of source) {
69
+ if (data.length >= authTagLength) {
70
+ yield cipher.update(authTag);
71
+ authTag = data.slice(data.length - authTagLength);
72
+ yield cipher.update(data.slice(0, data.length - authTagLength));
73
+ } else {
74
+ const fullData = Buffer.concat([authTag, data]);
75
+ const fullDataLength = fullData.length;
76
+ if (fullDataLength > authTagLength) {
77
+ authTag = fullData.slice(fullDataLength - authTagLength);
78
+ yield cipher.update(fullData.slice(0, fullDataLength - authTagLength));
79
+ } else {
80
+ authTag = fullData;
81
+ }
82
+ }
83
+ }
84
+ if (authTagLength > 0) {
85
+ cipher.setAuthTag(authTag);
86
+ }
87
+ yield cipher.final();
88
+ }, () => {});
40
89
  }
41
-
42
90
  function encryptData(buffer) {
43
91
  const iv = crypto.randomBytes(ivLength);
44
92
  const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv);
45
93
  const encrypted = cipher.update(buffer);
46
- return Buffer.concat([iv, encrypted, cipher.final()]);
94
+ return Buffer.concat([iv, encrypted, cipher.final(), authTagLength > 0 ? cipher.getAuthTag() : Buffer.alloc(0)]);
47
95
  }
48
-
49
96
  function decryptData(buffer) {
50
97
  const iv = buffer.slice(0, ivLength);
51
- const encrypted = buffer.slice(ivLength);
52
98
  const decipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv);
99
+ let encrypted;
100
+ if (authTagLength > 0) {
101
+ const authTag = buffer.slice(buffer.length - authTagLength);
102
+ decipher.setAuthTag(authTag);
103
+ encrypted = buffer.slice(ivLength, buffer.length - authTagLength);
104
+ } else {
105
+ encrypted = buffer.slice(ivLength);
106
+ }
53
107
  const decrypted = decipher.update(encrypted);
54
108
  return Buffer.concat([decrypted, decipher.final()]);
55
109
  }
56
-
57
110
  return {
58
111
  id: algorithm,
59
112
  algorithm,
@@ -65,6 +118,5 @@ function getEncryptor(key) {
65
118
  decryptStream
66
119
  };
67
120
  }
68
-
69
121
  exports._getEncryptor = getEncryptor;
70
122
  //# sourceMappingURL=_encryptor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_encryptor.js","names":["readChunk","require","crypto","pumpify","getEncryptor","key","undefined","id","algorithm","ivLength","encryptData","buffer","encryptStream","stream","decryptData","decryptStream","input","iv","randomBytes","cipher","createCipheriv","Buffer","from","encrypted","unshift","encryptedStream","createDecipheriv","update","concat","final","slice","decipher","decrypted","exports","_getEncryptor"],"sources":["../src/_encryptor.js"],"sourcesContent":["const { readChunk } = require('@vates/read-chunk')\nconst crypto = require('crypto')\nconst pumpify = require('pumpify')\n\nfunction getEncryptor(key) {\n if (key === undefined) {\n return {\n id: 'NULL_ENCRYPTOR',\n algorithm: 'none',\n key: 'none',\n ivLength: 0,\n encryptData: buffer => buffer,\n encryptStream: stream => stream,\n decryptData: buffer => buffer,\n decryptStream: stream => stream,\n }\n }\n const algorithm = 'aes-256-cbc'\n const ivLength = 16\n\n function encryptStream(input) {\n const iv = crypto.randomBytes(ivLength)\n const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv)\n\n const encrypted = pumpify(input, cipher)\n encrypted.unshift(iv)\n return encrypted\n }\n\n async function decryptStream(encryptedStream) {\n const iv = await readChunk(encryptedStream, ivLength)\n const cipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv)\n /**\n * WARNING\n *\n * the crytped size has an initializtion vector + a padding at the end\n * whe can't predict the decrypted size from the start of the encrypted size\n * thus, we can't set decrypted.length reliably\n *\n */\n return pumpify(encryptedStream, cipher)\n }\n\n function encryptData(buffer) {\n const iv = crypto.randomBytes(ivLength)\n const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv)\n const encrypted = cipher.update(buffer)\n return Buffer.concat([iv, encrypted, cipher.final()])\n }\n\n function decryptData(buffer) {\n const iv = buffer.slice(0, ivLength)\n const encrypted = buffer.slice(ivLength)\n const decipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv)\n const decrypted = decipher.update(encrypted)\n return Buffer.concat([decrypted, decipher.final()])\n }\n\n return {\n id: algorithm,\n algorithm,\n key,\n ivLength,\n encryptData,\n encryptStream,\n decryptData,\n decryptStream,\n }\n}\n\nexports._getEncryptor = getEncryptor\n"],"mappings":";;AAAA,MAAM;EAAEA;AAAF,IAAgBC,OAAO,CAAC,mBAAD,CAA7B;;AACA,MAAMC,MAAM,GAAGD,OAAO,CAAC,QAAD,CAAtB;;AACA,MAAME,OAAO,GAAGF,OAAO,CAAC,SAAD,CAAvB;;AAEA,SAASG,YAAT,CAAsBC,GAAtB,EAA2B;EACzB,IAAIA,GAAG,KAAKC,SAAZ,EAAuB;IACrB,OAAO;MACLC,EAAE,EAAE,gBADC;MAELC,SAAS,EAAE,MAFN;MAGLH,GAAG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,CAACQ,MAAP,CAAchB,MAAd,CAAlB;IACA,OAAOU,MAAM,CAACO,MAAP,CAAc,CAACX,EAAD,EAAKM,SAAL,EAAgBJ,MAAM,CAACU,KAAP,EAAhB,CAAd,CAAP;EACD;;EAED,SAASf,WAAT,CAAqBH,MAArB,EAA6B;IAC3B,MAAMM,EAAE,GAAGN,MAAM,CAACmB,KAAP,CAAa,CAAb,EAAgBrB,QAAhB,CAAX;IACA,MAAMc,SAAS,GAAGZ,MAAM,CAACmB,KAAP,CAAarB,QAAb,CAAlB;IACA,MAAMsB,QAAQ,GAAG7B,MAAM,CAACwB,gBAAP,CAAwBlB,SAAxB,EAAmCa,MAAM,CAACC,IAAP,CAAYjB,GAAZ,CAAnC,EAAqDY,EAArD,CAAjB;IACA,MAAMe,SAAS,GAAGD,QAAQ,CAACJ,MAAT,CAAgBJ,SAAhB,CAAlB;IACA,OAAOF,MAAM,CAACO,MAAP,CAAc,CAACI,SAAD,EAAYD,QAAQ,CAACF,KAAT,EAAZ,CAAd,CAAP;EACD;;EAED,OAAO;IACLtB,EAAE,EAAEC,SADC;IAELA,SAFK;IAGLH,GAHK;IAILI,QAJK;IAKLC,WALK;IAMLE,aANK;IAOLE,WAPK;IAQLC;EARK,CAAP;AAUD;;AAEDkB,OAAO,CAACC,aAAR,GAAwB9B,YAAxB"}
1
+ {"version":3,"file":"_encryptor.js","names":["pipeline","require","readChunk","crypto","DEFAULT_ENCRYPTION_ALGORITHM","UNENCRYPTED_ALGORITHM","isLegacyEncryptionAlgorithm","algorithm","getEncryptor","key","undefined","id","ivLength","encryptData","buffer","encryptStream","stream","decryptData","decryptStream","info","getCipherInfo","keyLength","length","error","Error","getCiphers","code","mode","authTagLength","includes","input","source","iv","randomBytes","cipher","createCipheriv","Buffer","from","data","update","final","getAuthTag","encryptedStream","createDecipheriv","authTag","alloc","slice","fullData","concat","fullDataLength","setAuthTag","encrypted","decipher","decrypted","exports","_getEncryptor"],"sources":["../src/_encryptor.js"],"sourcesContent":["const { pipeline } = require('node:stream')\nconst { readChunk } = require('@vates/read-chunk')\nconst crypto = require('crypto')\n\nexport const DEFAULT_ENCRYPTION_ALGORITHM = 'aes-256-gcm'\nexport const UNENCRYPTED_ALGORITHM = 'none'\n\nexport function isLegacyEncryptionAlgorithm(algorithm) {\n return algorithm !== UNENCRYPTED_ALGORITHM && algorithm !== DEFAULT_ENCRYPTION_ALGORITHM\n}\n\nfunction getEncryptor(algorithm = DEFAULT_ENCRYPTION_ALGORITHM, key) {\n if (key === undefined) {\n return {\n id: 'NULL_ENCRYPTOR',\n algorithm: 'none',\n key: 'none',\n ivLength: 0,\n encryptData: buffer => buffer,\n encryptStream: stream => stream,\n decryptData: buffer => buffer,\n decryptStream: stream => stream,\n }\n }\n const info = crypto.getCipherInfo(algorithm, { keyLength: key.length })\n if (info === undefined) {\n const error = new Error(\n `Either the algorithm ${algorithm} is not available, or the key length ${\n key.length\n } is incorrect. Supported algorithm are ${crypto.getCiphers()}`\n )\n error.code = 'BAD_ALGORITHM'\n throw error\n }\n const { ivLength, mode } = info\n const authTagLength = ['gcm', 'ccm', 'ocb'].includes(mode) ? 16 : 0\n\n function encryptStream(input) {\n return pipeline(\n input,\n async function* (source) {\n const iv = crypto.randomBytes(ivLength)\n const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv)\n yield iv\n for await (const data of source) {\n yield cipher.update(data)\n }\n yield cipher.final()\n // must write the auth tag at the end of the encryption stream\n if (authTagLength > 0) {\n yield cipher.getAuthTag()\n }\n },\n () => {}\n )\n }\n\n function decryptStream(encryptedStream) {\n return pipeline(\n encryptedStream,\n async function* (source) {\n /**\n * WARNING\n *\n * the crypted size has an initializtion vector + eventually an auth tag + a padding at the end\n * whe can't predict the decrypted size from the start of the encrypted size\n * thus, we can't set decrypted.length reliably\n *\n */\n\n const iv = await readChunk(source, ivLength)\n const cipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv)\n let authTag = Buffer.alloc(0)\n for await (const data of source) {\n if (data.length >= authTagLength) {\n // fast path, no buffer concat\n yield cipher.update(authTag)\n authTag = data.slice(data.length - authTagLength)\n yield cipher.update(data.slice(0, data.length - authTagLength))\n } else {\n // slower since there is a concat\n const fullData = Buffer.concat([authTag, data])\n const fullDataLength = fullData.length\n if (fullDataLength > authTagLength) {\n authTag = fullData.slice(fullDataLength - authTagLength)\n yield cipher.update(fullData.slice(0, fullDataLength - authTagLength))\n } else {\n authTag = fullData\n }\n }\n }\n if (authTagLength > 0) {\n cipher.setAuthTag(authTag)\n }\n yield cipher.final()\n },\n () => {}\n )\n }\n\n function encryptData(buffer) {\n const iv = crypto.randomBytes(ivLength)\n const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv)\n const encrypted = cipher.update(buffer)\n return Buffer.concat([iv, encrypted, cipher.final(), authTagLength > 0 ? cipher.getAuthTag() : Buffer.alloc(0)])\n }\n\n function decryptData(buffer) {\n const iv = buffer.slice(0, ivLength)\n const decipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv)\n let encrypted\n if (authTagLength > 0) {\n const authTag = buffer.slice(buffer.length - authTagLength)\n decipher.setAuthTag(authTag)\n encrypted = buffer.slice(ivLength, buffer.length - authTagLength)\n } else {\n encrypted = buffer.slice(ivLength)\n }\n const decrypted = decipher.update(encrypted)\n return Buffer.concat([decrypted, decipher.final()])\n }\n\n return {\n id: algorithm,\n algorithm,\n key,\n ivLength,\n encryptData,\n encryptStream,\n decryptData,\n decryptStream,\n }\n}\n\nexports._getEncryptor = getEncryptor\n"],"mappings":";;;;;;;AAAA,MAAM;EAAEA;AAAS,CAAC,GAAGC,OAAO,CAAC,aAAa,CAAC;AAC3C,MAAM;EAAEC;AAAU,CAAC,GAAGD,OAAO,CAAC,mBAAmB,CAAC;AAClD,MAAME,MAAM,GAAGF,OAAO,CAAC,QAAQ,CAAC;AAEzB,MAAMG,4BAA4B,GAAG,aAAa;AAAA;AAClD,MAAMC,qBAAqB,GAAG,MAAM;AAAA;AAEpC,SAASC,2BAA2B,CAACC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AAE,CAAC;IACzE,IAAImB,SAAS;IACb,IAAIvB,aAAa,GAAG,CAAC,EAAE;MACrB,MAAMgB,OAAO,GAAG9B,MAAM,CAACgC,KAAK,CAAChC,MAAM,CAACQ,MAAM,GAAGM,aAAa,CAAC;MAC3DwB,QAAQ,CAACF,UAAU,CAACN,OAAO,CAAC;MAC5BO,SAAS,GAAGrC,MAAM,CAACgC,KAAK,CAAClC,QAAQ,EAAEE,MAAM,CAACQ,MAAM,GAAGM,aAAa,CAAC;IACnE,CAAC,MAAM;MACLuB,SAAS,GAAGrC,MAAM,CAACgC,KAAK,CAAClC,QAAQ,CAAC;IACpC;IACA,MAAMyC,SAAS,GAAGD,QAAQ,CAACb,MAAM,CAACY,SAAS,CAAC;IAC5C,OAAOf,MAAM,CAACY,MAAM,CAAC,CAACK,SAAS,EAAED,QAAQ,CAACZ,KAAK,EAAE,CAAC,CAAC;EACrD;EAEA,OAAO;IACL7B,EAAE,EAAEJ,SAAS;IACbA,SAAS;IACTE,GAAG;IACHG,QAAQ;IACRC,WAAW;IACXE,aAAa;IACbE,WAAW;IACXC;EACF,CAAC;AACH;AAEAoC,OAAO,CAACC,aAAa,GAAG/C,YAAY"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = guessAwsRegion;
7
-
8
7
  function guessAwsRegion(host) {
9
8
  const matches = /^s3\.([^.]+)\.amazonaws.com$/.exec(host);
10
9
  return matches !== null ? matches[1] : 'us-east-1';
@@ -1 +1 @@
1
- {"version":3,"file":"_guessAwsRegion.js","names":["guessAwsRegion","host","matches","exec"],"sources":["../src/_guessAwsRegion.js"],"sourcesContent":["export default function guessAwsRegion(host) {\n const matches = /^s3\\.([^.]+)\\.amazonaws.com$/.exec(host)\n return matches !== null ? matches[1] : 'us-east-1'\n}\n"],"mappings":";;;;;;;AAAe,SAASA,cAAT,CAAwBC,IAAxB,EAA8B;EAC3C,MAAMC,OAAO,GAAG,+BAA+BC,IAA/B,CAAoCF,IAApC,CAAhB;EACA,OAAOC,OAAO,KAAK,IAAZ,GAAmBA,OAAO,CAAC,CAAD,CAA1B,GAAgC,WAAvC;AACD"}
1
+ {"version":3,"file":"_guessAwsRegion.js","names":["guessAwsRegion","host","matches","exec"],"sources":["../src/_guessAwsRegion.js"],"sourcesContent":["export default function guessAwsRegion(host) {\n const matches = /^s3\\.([^.]+)\\.amazonaws.com$/.exec(host)\n return matches !== null ? matches[1] : 'us-east-1'\n}\n"],"mappings":";;;;;;AAAe,SAASA,cAAc,CAACC,IAAI,EAAE;EAC3C,MAAMC,OAAO,GAAG,8BAA8B,CAACC,IAAI,CAACF,IAAI,CAAC;EACzD,OAAOC,OAAO,KAAK,IAAI,GAAGA,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW;AACpD"}
package/dist/_mount.js CHANGED
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _execa = _interopRequireDefault(require("execa"));
9
-
10
8
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
-
12
9
  var _promiseToolbox = require("promise-toolbox");
13
-
14
10
  var _path = require("path");
15
-
16
11
  var _os = require("os");
17
-
18
12
  var _local = _interopRequireDefault(require("./local"));
19
-
20
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
14
  const sudoExeca = (command, args, opts) => (0, _execa.default)('sudo', [command, ...args], opts);
23
-
24
15
  class MountHandler extends _local.default {
25
16
  constructor(remote, {
26
17
  mountsDir = (0, _path.join)((0, _os.tmpdir)(), 'xo-fs-mounts'),
@@ -30,19 +21,17 @@ class MountHandler extends _local.default {
30
21
  super(remote, opts);
31
22
  this._execa = useSudo ? sudoExeca : _execa.default;
32
23
  this._keeper = undefined;
33
- this._params = { ...params,
24
+ this._params = {
25
+ ...params,
34
26
  options: [params.options, remote.options ?? params.defaultOptions].filter(_ => _ !== undefined).join(',')
35
27
  };
36
28
  this._realPath = (0, _path.join)(mountsDir, remote.id || Math.random().toString(36).slice(2));
37
29
  }
38
-
39
30
  async _forget() {
40
31
  const keeper = this._keeper;
41
-
42
32
  if (keeper === undefined) {
43
33
  return;
44
34
  }
45
-
46
35
  this._keeper = undefined;
47
36
  await _fsExtra.default.close(keeper);
48
37
  await _promiseToolbox.ignoreErrors.call(this._execa('umount', [this._getRealPath()], {
@@ -51,26 +40,19 @@ class MountHandler extends _local.default {
51
40
  }
52
41
  }));
53
42
  }
54
-
55
43
  _getRealPath() {
56
44
  return this._realPath;
57
45
  }
58
-
59
46
  async _sync() {
60
47
  {
61
48
  const keeper = this._keeper;
62
-
63
49
  if (keeper !== undefined) {
64
50
  this._keeper = undefined;
65
-
66
51
  _promiseToolbox.ignoreErrors.call(_fsExtra.default.close(keeper));
67
52
  }
68
53
  }
69
-
70
54
  const realPath = this._getRealPath();
71
-
72
55
  await _fsExtra.default.ensureDir(realPath);
73
-
74
56
  try {
75
57
  const {
76
58
  type,
@@ -78,6 +60,7 @@ class MountHandler extends _local.default {
78
60
  options,
79
61
  env
80
62
  } = this._params;
63
+
81
64
  await this._execa('mount', ['-o', options, '-t', type, device, realPath], {
82
65
  env: {
83
66
  LANG: 'C',
@@ -96,11 +79,8 @@ class MountHandler extends _local.default {
96
79
 
97
80
  const keeperPath = `${realPath}/.keeper_${Math.random().toString(36).slice(2)}`;
98
81
  this._keeper = await _fsExtra.default.open(keeperPath, 'w');
99
-
100
82
  _promiseToolbox.ignoreErrors.call(_fsExtra.default.unlink(keeperPath));
101
83
  }
102
-
103
84
  }
104
-
105
85
  exports.default = MountHandler;
106
86
  //# sourceMappingURL=_mount.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_mount.js","names":["sudoExeca","command","args","opts","execa","MountHandler","LocalHandler","constructor","remote","mountsDir","join","tmpdir","useSudo","params","_execa","_keeper","undefined","_params","options","defaultOptions","filter","_","_realPath","id","Math","random","toString","slice","_forget","keeper","fs","close","ignoreErrors","call","_getRealPath","env","LANG","_sync","realPath","ensureDir","type","device","error","stdio","keeperPath","open","unlink"],"sources":["../src/_mount.js"],"sourcesContent":["import execa from 'execa'\nimport fs from 'fs-extra'\nimport { ignoreErrors } from 'promise-toolbox'\nimport { join } from 'path'\nimport { tmpdir } from 'os'\n\nimport LocalHandler from './local'\n\nconst sudoExeca = (command, args, opts) => execa('sudo', [command, ...args], opts)\n\nexport default class MountHandler extends LocalHandler {\n constructor(remote, { mountsDir = join(tmpdir(), 'xo-fs-mounts'), useSudo = false, ...opts } = {}, params) {\n super(remote, opts)\n\n this._execa = useSudo ? sudoExeca : execa\n this._keeper = undefined\n this._params = {\n ...params,\n options: [params.options, remote.options ?? params.defaultOptions].filter(_ => _ !== undefined).join(','),\n }\n this._realPath = join(mountsDir, remote.id || Math.random().toString(36).slice(2))\n }\n\n async _forget() {\n const keeper = this._keeper\n if (keeper === undefined) {\n return\n }\n this._keeper = undefined\n await fs.close(keeper)\n\n await ignoreErrors.call(\n this._execa('umount', [this._getRealPath()], {\n env: {\n LANG: 'C',\n },\n })\n )\n }\n\n _getRealPath() {\n return this._realPath\n }\n\n async _sync() {\n // in case of multiple `sync`s, ensure we properly close previous keeper\n {\n const keeper = this._keeper\n if (keeper !== undefined) {\n this._keeper = undefined\n ignoreErrors.call(fs.close(keeper))\n }\n }\n\n const realPath = this._getRealPath()\n\n await fs.ensureDir(realPath)\n\n try {\n const { type, device, options, env } = this._params\n\n // Linux mount is more flexible in which order the mount arguments appear.\n // But FreeBSD requires this order of the arguments.\n await this._execa('mount', ['-o', options, '-t', type, device, realPath], {\n env: {\n LANG: 'C',\n ...env,\n },\n })\n } catch (error) {\n try {\n // the failure may mean it's already mounted, use `findmnt` to check\n // that's the case\n await this._execa('findmnt', [realPath], {\n stdio: 'ignore',\n })\n } catch (_) {\n throw error\n }\n }\n\n // keep an open file on the mount to prevent it from being unmounted if used\n // by another handler/process\n const keeperPath = `${realPath}/.keeper_${Math.random().toString(36).slice(2)}`\n this._ke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AAd,CAAuB,EAAvB,EAA2BC,KAA3B,CAAiC,CAAjC,CAAoC,EAA9E;IACA,KAAKZ,OAAL,GAAe,MAAMe,gBAAA,CAAGe,IAAH,CAAQD,UAAR,EAAoB,GAApB,CAArB;;IACAZ,4BAAA,CAAaC,IAAb,CAAkBH,gBAAA,CAAGgB,MAAH,CAAUF,UAAV,CAAlB;EACD;;AA5EoD"}
1
+ {"version":3,"file":"_mount.js","names":["sudoExeca","command","args","opts","execa","MountHandler","LocalHandler","constructor","remote","mountsDir","join","tmpdir","useSudo","params","_execa","_keeper","undefined","_params","options","defaultOptions","filter","_","_realPath","id","Math","random","toString","slice","_forget","keeper","fs","close","ignoreErrors","call","_getRealPath","env","LANG","_sync","realPath","ensureDir","type","device","error","stdio","keeperPath","open","unlink"],"sources":["../src/_mount.js"],"sourcesContent":["import execa from 'execa'\nimport fs from 'fs-extra'\nimport { ignoreErrors } from 'promise-toolbox'\nimport { join } from 'path'\nimport { tmpdir } from 'os'\n\nimport LocalHandler from './local'\n\nconst sudoExeca = (command, args, opts) => execa('sudo', [command, ...args], opts)\n\nexport default class MountHandler extends LocalHandler {\n constructor(remote, { mountsDir = join(tmpdir(), 'xo-fs-mounts'), useSudo = false, ...opts } = {}, params) {\n super(remote, opts)\n\n this._execa = useSudo ? sudoExeca : execa\n this._keeper = undefined\n this._params = {\n ...params,\n options: [params.options, remote.options ?? params.defaultOptions].filter(_ => _ !== undefined).join(','),\n }\n this._realPath = join(mountsDir, remote.id || Math.random().toString(36).slice(2))\n }\n\n async _forget() {\n const keeper = this._keeper\n if (keeper === undefined) {\n return\n }\n this._keeper = undefined\n await fs.close(keeper)\n\n await ignoreErrors.call(\n this._execa('umount', [this._getRealPath()], {\n env: {\n LANG: 'C',\n },\n })\n )\n }\n\n _getRealPath() {\n return this._realPath\n }\n\n async _sync() {\n // in case of multiple `sync`s, ensure we properly close previous keeper\n {\n const keeper = this._keeper\n if (keeper !== undefined) {\n this._keeper = undefined\n ignoreErrors.call(fs.close(keeper))\n }\n }\n\n const realPath = this._getRealPath()\n\n await fs.ensureDir(realPath)\n\n try {\n const { type, device, options, env } = this._params\n\n // Linux mount is more flexible in which order the mount arguments appear.\n // But FreeBSD requires this order of the arguments.\n await this._execa('mount', ['-o', options, '-t', type, device, realPath], {\n env: {\n LANG: 'C',\n ...env,\n },\n })\n } catch (error) {\n try {\n // the failure may mean it's already mounted, use `findmnt` to check\n // that's the case\n await this._execa('findmnt', [realPath], {\n stdio: 'ignore',\n })\n } catch (_) {\n throw error\n }\n }\n\n // keep an open file on the mount to prevent it from being unmounted if used\n // by another handler/process\n const keeperPath = `${realPath}/.keeper_${Math.random().toString(36).slice(2)}`\n this._keeper = await fs.open(keeperPath, 'w')\n ignoreErrors.call(fs.unlink(keeperPath))\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA;AAAkC;AAElC,MAAMA,SAAS,GAAG,CAACC,OAAO,EAAEC,IAAI,EAAEC,IAAI,KAAK,IAAAC,cAAK,EAAC,MAAM,EAAE,CAACH,OAAO,EAAE,GAAGC,IAAI,CAAC,EAAEC,IAAI,CAAC;AAEnE,MAAME,YAAY,SAASC,cAAY,CAAC;EACrDC,WAAW,CAACC,MAAM,EAAE;IAAEC,SAAS,GAAG,IAAAC,UAAI,EAAC,IAAAC,UAAM,GAAE,EAAE,cAAc,CAAC;IAAEC,OAAO,GAAG,KAAK;IAAE,GAAGT;EAAK,CAAC,GAAG,CAAC,CAAC,EAAEU,MAAM,EAAE;IACzG,KAAK,CAACL,MAAM,EAAEL,IAAI,CAAC;IAEnB,IAAI,CAACW,MAAM,GAAGF,OAAO,GAAGZ,SAAS,GAAGI,cAAK;IACzC,IAAI,CAACW,OAAO,GAAGC,SAAS;IACxB,IAAI,CAACC,OAAO,GAAG;MACb,GAAGJ,MAAM;MACTK,OAAO,EAAE,CAACL,MAAM,CAACK,OAAO,EAAEV,MAAM,CAACU,OAAO,IAAIL,MAAM,CAACM,cAAc,CAAC,CAACC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