read-excel-file 5.3.5 → 5.4.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/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 5.4.0 / 04.07.2022
2
+ ==================
3
+
4
+ * [Fixed](https://gitlab.com/catamphetamine/read-excel-file/-/issues/54) non-ASCII character encoding by forcing Node.js version of the library to read zipped contents of an XLSX file in UTF-8 character encoding. I suppose it won't break the existing code.
5
+
1
6
  5.3.5 / 26.06.2022
2
7
  ==================
3
8
 
@@ -36,6 +36,20 @@ function unpackXlsxFile(input) {
36
36
  var contents = ''; // To ignore an entry: `entry.autodrain()`.
37
37
 
38
38
  entryPromises.push(new Promise(function (resolve) {
39
+ // It's not clear what encoding are the files inside XLSX in.
40
+ // https://stackoverflow.com/questions/45194771/are-xlsx-files-utf-8-encoded-by-definition
41
+ // For example, for XML files, encoding is specified at the top node:
42
+ // `<?xml version="1.0" encoding="UTF-8"/>`.
43
+ //
44
+ // `unzipper` supports setting encoding when reading an `entry`.
45
+ // https://github.com/ZJONSSON/node-unzipper/issues/35
46
+ // https://gitlab.com/catamphetamine/read-excel-file/-/issues/54
47
+ //
48
+ // If the `entry.setEncoding('utf8')` line would be commented out,
49
+ // there's a `nonAsciiCharacterEncoding` test that wouldn't pass.
50
+ //
51
+ entry.setEncoding('utf8'); //
52
+
39
53
  entry.on('data', function (data) {
40
54
  return contents += data.toString();
41
55
  }).on('end', function () {
@@ -1 +1 @@
1
- {"version":3,"file":"unpackXlsxFileNode.js","names":["unpackXlsxFile","input","entries","stream","Stream","fs","createReadStream","Promise","resolve","reject","entryPromises","on","pipe","unzip","Parse","all","then","entry","contents","push","data","toString","path"],"sources":["../../source/read/unpackXlsxFileNode.js"],"sourcesContent":["import fs from 'fs'\r\nimport Stream from 'stream'\r\nimport unzip from 'unzipper'\r\n\r\n/**\r\n * Reads XLSX file in Node.js.\r\n * @param {(string|Stream)} input - A Node.js readable stream or a path to a file.\r\n * @return {Promise} Resolves to an object holding XLSX file entries.\r\n */\r\nexport default function unpackXlsxFile(input) {\r\n // XLSX file is a zip archive.\r\n // The `entries` object stores the files\r\n // and their contents from this XLSX zip archive.\r\n const entries = {}\r\n\r\n const stream = input instanceof Stream ? input : fs.createReadStream(input)\r\n\r\n return new Promise((resolve, reject) => {\r\n const entryPromises = []\r\n\r\n stream\r\n // This first \"error\" listener is for the original stream errors.\r\n .on('error', reject)\r\n .pipe(unzip.Parse())\r\n // This second \"error\" listener is for the unzip stream errors.\r\n .on('error', reject)\r\n .on('close', () => Promise.all(entryPromises).then(() => resolve(entries)))\r\n .on('entry', (entry) => {\r\n let contents = ''\r\n // To ignore an entry: `entry.autodrain()`.\r\n entryPromises.push(new Promise((resolve) => {\r\n entry\r\n .on('data', data => contents += data.toString())\r\n .on('end', () => resolve(entries[entry.path] = contents))\r\n }))\r\n })\r\n })\r\n}\r\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwBC,KAAxB,EAA+B;EAC5C;EACA;EACA;EACA,IAAMC,OAAO,GAAG,EAAhB;EAEA,IAAMC,MAAM,GAAGF,KAAK,YAAYG,kBAAjB,GAA0BH,KAA1B,GAAkCI,cAAA,CAAGC,gBAAH,CAAoBL,KAApB,CAAjD;EAEA,OAAO,IAAIM,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;IACtC,IAAMC,aAAa,GAAG,EAAtB;IAEAP,MAAM,CACJ;IADI,CAEHQ,EAFH,CAEM,OAFN,EAEeF,MAFf,EAGGG,IAHH,CAGQC,oBAAA,CAAMC,KAAN,EAHR,EAIE;IAJF,CAKGH,EALH,CAKM,OALN,EAKeF,MALf,EAMGE,EANH,CAMM,OANN,EAMe;MAAA,OAAOJ,OAAO,CAACQ,GAAR,CAAYL,aAAZ,EAA2BM,IAA3B,CAAgC;QAAA,OAAMR,OAAO,CAACN,OAAD,CAAb;MAAA,CAAhC,CAAP;IAAA,CANf,EAOGS,EAPH,CAOM,OAPN,EAOe,UAACM,KAAD,EAAW;MACtB,IAAIC,QAAQ,GAAG,EAAf,CADsB,CAEtB;;MACAR,aAAa,CAACS,IAAd,CAAmB,IAAIZ,OAAJ,CAAY,UAACC,OAAD,EAAa;QAC1CS,KAAK,CACFN,EADH,CACM,MADN,EACc,UAAAS,IAAI;UAAA,OAAIF,QAAQ,IAAIE,IAAI,CAACC,QAAL,EAAhB;QAAA,CADlB,EAEGV,EAFH,CAEM,KAFN,EAEa;UAAA,OAAMH,OAAO,CAACN,OAAO,CAACe,KAAK,CAACK,IAAP,CAAP,GAAsBJ,QAAvB,CAAb;QAAA,CAFb;MAGD,CAJkB,CAAnB;IAKD,CAfH;EAgBD,CAnBM,CAAP;AAoBD"}
1
+ {"version":3,"file":"unpackXlsxFileNode.js","names":["unpackXlsxFile","input","entries","stream","Stream","fs","createReadStream","Promise","resolve","reject","entryPromises","on","pipe","unzip","Parse","all","then","entry","contents","push","setEncoding","data","toString","path"],"sources":["../../source/read/unpackXlsxFileNode.js"],"sourcesContent":["import fs from 'fs'\r\nimport Stream from 'stream'\r\nimport unzip from 'unzipper'\r\n\r\n/**\r\n * Reads XLSX file in Node.js.\r\n * @param {(string|Stream)} input - A Node.js readable stream or a path to a file.\r\n * @return {Promise} Resolves to an object holding XLSX file entries.\r\n */\r\nexport default function unpackXlsxFile(input) {\r\n // XLSX file is a zip archive.\r\n // The `entries` object stores the files\r\n // and their contents from this XLSX zip archive.\r\n const entries = {}\r\n\r\n const stream = input instanceof Stream ? input : fs.createReadStream(input)\r\n\r\n return new Promise((resolve, reject) => {\r\n const entryPromises = []\r\n\r\n stream\r\n // This first \"error\" listener is for the original stream errors.\r\n .on('error', reject)\r\n .pipe(unzip.Parse())\r\n // This second \"error\" listener is for the unzip stream errors.\r\n .on('error', reject)\r\n .on('close', () => Promise.all(entryPromises).then(() => resolve(entries)))\r\n .on('entry', (entry) => {\r\n let contents = ''\r\n // To ignore an entry: `entry.autodrain()`.\r\n entryPromises.push(new Promise((resolve) => {\r\n // It's not clear what encoding are the files inside XLSX in.\r\n // https://stackoverflow.com/questions/45194771/are-xlsx-files-utf-8-encoded-by-definition\r\n // For example, for XML files, encoding is specified at the top node:\r\n // `<?xml version=\"1.0\" encoding=\"UTF-8\"/>`.\r\n //\r\n // `unzipper` supports setting encoding when reading an `entry`.\r\n // https://github.com/ZJONSSON/node-unzipper/issues/35\r\n // https://gitlab.com/catamphetamine/read-excel-file/-/issues/54\r\n //\r\n // If the `entry.setEncoding('utf8')` line would be commented out,\r\n // there's a `nonAsciiCharacterEncoding` test that wouldn't pass.\r\n //\r\n entry.setEncoding('utf8')\r\n //\r\n entry\r\n .on('data', data => contents += data.toString())\r\n .on('end', () => resolve(entries[entry.path] = contents))\r\n }))\r\n })\r\n })\r\n}\r\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwBC,KAAxB,EAA+B;EAC5C;EACA;EACA;EACA,IAAMC,OAAO,GAAG,EAAhB;EAEA,IAAMC,MAAM,GAAGF,KAAK,YAAYG,kBAAjB,GAA0BH,KAA1B,GAAkCI,cAAA,CAAGC,gBAAH,CAAoBL,KAApB,CAAjD;EAEA,OAAO,IAAIM,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;IACtC,IAAMC,aAAa,GAAG,EAAtB;IAEAP,MAAM,CACJ;IADI,CAEHQ,EAFH,CAEM,OAFN,EAEeF,MAFf,EAGGG,IAHH,CAGQC,oBAAA,CAAMC,KAAN,EAHR,EAIE;IAJF,CAKGH,EALH,CAKM,OALN,EAKeF,MALf,EAMGE,EANH,CAMM,OANN,EAMe;MAAA,OAAOJ,OAAO,CAACQ,GAAR,CAAYL,aAAZ,EAA2BM,IAA3B,CAAgC;QAAA,OAAMR,OAAO,CAACN,OAAD,CAAb;MAAA,CAAhC,CAAP;IAAA,CANf,EAOGS,EAPH,CAOM,OAPN,EAOe,UAACM,KAAD,EAAW;MACtB,IAAIC,QAAQ,GAAG,EAAf,CADsB,CAEtB;;MACAR,aAAa,CAACS,IAAd,CAAmB,IAAIZ,OAAJ,CAAY,UAACC,OAAD,EAAa;QAC1C;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACAS,KAAK,CAACG,WAAN,CAAkB,MAAlB,EAb0C,CAc1C;;QACAH,KAAK,CACFN,EADH,CACM,MADN,EACc,UAAAU,IAAI;UAAA,OAAIH,QAAQ,IAAIG,IAAI,CAACC,QAAL,EAAhB;QAAA,CADlB,EAEGX,EAFH,CAEM,KAFN,EAEa;UAAA,OAAMH,OAAO,CAACN,OAAO,CAACe,KAAK,CAACM,IAAP,CAAP,GAAsBL,QAAvB,CAAb;QAAA,CAFb;MAGD,CAlBkB,CAAnB;IAmBD,CA7BH;EA8BD,CAjCM,CAAP;AAkCD"}
@@ -25,6 +25,20 @@ export default function unpackXlsxFile(input) {
25
25
  var contents = ''; // To ignore an entry: `entry.autodrain()`.
26
26
 
27
27
  entryPromises.push(new Promise(function (resolve) {
28
+ // It's not clear what encoding are the files inside XLSX in.
29
+ // https://stackoverflow.com/questions/45194771/are-xlsx-files-utf-8-encoded-by-definition
30
+ // For example, for XML files, encoding is specified at the top node:
31
+ // `<?xml version="1.0" encoding="UTF-8"/>`.
32
+ //
33
+ // `unzipper` supports setting encoding when reading an `entry`.
34
+ // https://github.com/ZJONSSON/node-unzipper/issues/35
35
+ // https://gitlab.com/catamphetamine/read-excel-file/-/issues/54
36
+ //
37
+ // If the `entry.setEncoding('utf8')` line would be commented out,
38
+ // there's a `nonAsciiCharacterEncoding` test that wouldn't pass.
39
+ //
40
+ entry.setEncoding('utf8'); //
41
+
28
42
  entry.on('data', function (data) {
29
43
  return contents += data.toString();
30
44
  }).on('end', function () {
@@ -1 +1 @@
1
- {"version":3,"file":"unpackXlsxFileNode.js","names":["fs","Stream","unzip","unpackXlsxFile","input","entries","stream","createReadStream","Promise","resolve","reject","entryPromises","on","pipe","Parse","all","then","entry","contents","push","data","toString","path"],"sources":["../../source/read/unpackXlsxFileNode.js"],"sourcesContent":["import fs from 'fs'\r\nimport Stream from 'stream'\r\nimport unzip from 'unzipper'\r\n\r\n/**\r\n * Reads XLSX file in Node.js.\r\n * @param {(string|Stream)} input - A Node.js readable stream or a path to a file.\r\n * @return {Promise} Resolves to an object holding XLSX file entries.\r\n */\r\nexport default function unpackXlsxFile(input) {\r\n // XLSX file is a zip archive.\r\n // The `entries` object stores the files\r\n // and their contents from this XLSX zip archive.\r\n const entries = {}\r\n\r\n const stream = input instanceof Stream ? input : fs.createReadStream(input)\r\n\r\n return new Promise((resolve, reject) => {\r\n const entryPromises = []\r\n\r\n stream\r\n // This first \"error\" listener is for the original stream errors.\r\n .on('error', reject)\r\n .pipe(unzip.Parse())\r\n // This second \"error\" listener is for the unzip stream errors.\r\n .on('error', reject)\r\n .on('close', () => Promise.all(entryPromises).then(() => resolve(entries)))\r\n .on('entry', (entry) => {\r\n let contents = ''\r\n // To ignore an entry: `entry.autodrain()`.\r\n entryPromises.push(new Promise((resolve) => {\r\n entry\r\n .on('data', data => contents += data.toString())\r\n .on('end', () => resolve(entries[entry.path] = contents))\r\n }))\r\n })\r\n })\r\n}\r\n"],"mappings":"AAAA,OAAOA,EAAP,MAAe,IAAf;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,OAAOC,KAAP,MAAkB,UAAlB;AAEA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,cAAT,CAAwBC,KAAxB,EAA+B;EAC5C;EACA;EACA;EACA,IAAMC,OAAO,GAAG,EAAhB;EAEA,IAAMC,MAAM,GAAGF,KAAK,YAAYH,MAAjB,GAA0BG,KAA1B,GAAkCJ,EAAE,CAACO,gBAAH,CAAoBH,KAApB,CAAjD;EAEA,OAAO,IAAII,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;IACtC,IAAMC,aAAa,GAAG,EAAtB;IAEAL,MAAM,CACJ;IADI,CAEHM,EAFH,CAEM,OAFN,EAEeF,MAFf,EAGGG,IAHH,CAGQX,KAAK,CAACY,KAAN,EAHR,EAIE;IAJF,CAKGF,EALH,CAKM,OALN,EAKeF,MALf,EAMGE,EANH,CAMM,OANN,EAMe;MAAA,OAAOJ,OAAO,CAACO,GAAR,CAAYJ,aAAZ,EAA2BK,IAA3B,CAAgC;QAAA,OAAMP,OAAO,CAACJ,OAAD,CAAb;MAAA,CAAhC,CAAP;IAAA,CANf,EAOGO,EAPH,CAOM,OAPN,EAOe,UAACK,KAAD,EAAW;MACtB,IAAIC,QAAQ,GAAG,EAAf,CADsB,CAEtB;;MACAP,aAAa,CAACQ,IAAd,CAAmB,IAAIX,OAAJ,CAAY,UAACC,OAAD,EAAa;QAC1CQ,KAAK,CACFL,EADH,CACM,MADN,EACc,UAAAQ,IAAI;UAAA,OAAIF,QAAQ,IAAIE,IAAI,CAACC,QAAL,EAAhB;QAAA,CADlB,EAEGT,EAFH,CAEM,KAFN,EAEa;UAAA,OAAMH,OAAO,CAACJ,OAAO,CAACY,KAAK,CAACK,IAAP,CAAP,GAAsBJ,QAAvB,CAAb;QAAA,CAFb;MAGD,CAJkB,CAAnB;IAKD,CAfH;EAgBD,CAnBM,CAAP;AAoBD"}
1
+ {"version":3,"file":"unpackXlsxFileNode.js","names":["fs","Stream","unzip","unpackXlsxFile","input","entries","stream","createReadStream","Promise","resolve","reject","entryPromises","on","pipe","Parse","all","then","entry","contents","push","setEncoding","data","toString","path"],"sources":["../../source/read/unpackXlsxFileNode.js"],"sourcesContent":["import fs from 'fs'\r\nimport Stream from 'stream'\r\nimport unzip from 'unzipper'\r\n\r\n/**\r\n * Reads XLSX file in Node.js.\r\n * @param {(string|Stream)} input - A Node.js readable stream or a path to a file.\r\n * @return {Promise} Resolves to an object holding XLSX file entries.\r\n */\r\nexport default function unpackXlsxFile(input) {\r\n // XLSX file is a zip archive.\r\n // The `entries` object stores the files\r\n // and their contents from this XLSX zip archive.\r\n const entries = {}\r\n\r\n const stream = input instanceof Stream ? input : fs.createReadStream(input)\r\n\r\n return new Promise((resolve, reject) => {\r\n const entryPromises = []\r\n\r\n stream\r\n // This first \"error\" listener is for the original stream errors.\r\n .on('error', reject)\r\n .pipe(unzip.Parse())\r\n // This second \"error\" listener is for the unzip stream errors.\r\n .on('error', reject)\r\n .on('close', () => Promise.all(entryPromises).then(() => resolve(entries)))\r\n .on('entry', (entry) => {\r\n let contents = ''\r\n // To ignore an entry: `entry.autodrain()`.\r\n entryPromises.push(new Promise((resolve) => {\r\n // It's not clear what encoding are the files inside XLSX in.\r\n // https://stackoverflow.com/questions/45194771/are-xlsx-files-utf-8-encoded-by-definition\r\n // For example, for XML files, encoding is specified at the top node:\r\n // `<?xml version=\"1.0\" encoding=\"UTF-8\"/>`.\r\n //\r\n // `unzipper` supports setting encoding when reading an `entry`.\r\n // https://github.com/ZJONSSON/node-unzipper/issues/35\r\n // https://gitlab.com/catamphetamine/read-excel-file/-/issues/54\r\n //\r\n // If the `entry.setEncoding('utf8')` line would be commented out,\r\n // there's a `nonAsciiCharacterEncoding` test that wouldn't pass.\r\n //\r\n entry.setEncoding('utf8')\r\n //\r\n entry\r\n .on('data', data => contents += data.toString())\r\n .on('end', () => resolve(entries[entry.path] = contents))\r\n }))\r\n })\r\n })\r\n}\r\n"],"mappings":"AAAA,OAAOA,EAAP,MAAe,IAAf;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,OAAOC,KAAP,MAAkB,UAAlB;AAEA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,cAAT,CAAwBC,KAAxB,EAA+B;EAC5C;EACA;EACA;EACA,IAAMC,OAAO,GAAG,EAAhB;EAEA,IAAMC,MAAM,GAAGF,KAAK,YAAYH,MAAjB,GAA0BG,KAA1B,GAAkCJ,EAAE,CAACO,gBAAH,CAAoBH,KAApB,CAAjD;EAEA,OAAO,IAAII,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;IACtC,IAAMC,aAAa,GAAG,EAAtB;IAEAL,MAAM,CACJ;IADI,CAEHM,EAFH,CAEM,OAFN,EAEeF,MAFf,EAGGG,IAHH,CAGQX,KAAK,CAACY,KAAN,EAHR,EAIE;IAJF,CAKGF,EALH,CAKM,OALN,EAKeF,MALf,EAMGE,EANH,CAMM,OANN,EAMe;MAAA,OAAOJ,OAAO,CAACO,GAAR,CAAYJ,aAAZ,EAA2BK,IAA3B,CAAgC;QAAA,OAAMP,OAAO,CAACJ,OAAD,CAAb;MAAA,CAAhC,CAAP;IAAA,CANf,EAOGO,EAPH,CAOM,OAPN,EAOe,UAACK,KAAD,EAAW;MACtB,IAAIC,QAAQ,GAAG,EAAf,CADsB,CAEtB;;MACAP,aAAa,CAACQ,IAAd,CAAmB,IAAIX,OAAJ,CAAY,UAACC,OAAD,EAAa;QAC1C;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACAQ,KAAK,CAACG,WAAN,CAAkB,MAAlB,EAb0C,CAc1C;;QACAH,KAAK,CACFL,EADH,CACM,MADN,EACc,UAAAS,IAAI;UAAA,OAAIH,QAAQ,IAAIG,IAAI,CAACC,QAAL,EAAhB;QAAA,CADlB,EAEGV,EAFH,CAEM,KAFN,EAEa;UAAA,OAAMH,OAAO,CAACJ,OAAO,CAACY,KAAK,CAACM,IAAP,CAAP,GAAsBL,QAAvB,CAAb;QAAA,CAFb;MAGD,CAlBkB,CAAnB;IAmBD,CA7BH;EA8BD,CAjCM,CAAP;AAkCD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "read-excel-file",
3
- "version": "5.3.5",
3
+ "version": "5.4.0",
4
4
  "description": "Read small to medium `*.xlsx` files in a browser or Node.js. Parse to JSON with a strict schema.",
5
5
  "module": "index.js",
6
6
  "main": "index.cjs",