libreoffice-convert 1.6.0 → 1.7.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/Readme.md CHANGED
@@ -4,7 +4,8 @@ A simple and fast node.js module for converting office documents to different fo
4
4
 
5
5
  ## Dependency
6
6
 
7
- Please install libreoffice in /Applications (Mac), with your favorite package manager (Linux), or with the msi (Windows).
7
+ Please install libreoffice in /Applications (Mac), with your favorite package manager (Linux), or with the msi (Windows)
8
+ (On Windows, add `PROGRAMFILES` environment variable for Windows program files path to your local project)
8
9
 
9
10
  ## Usage example
10
11
 
package/index.js CHANGED
@@ -24,9 +24,12 @@ const convertWithOptions = (document, format, filter, options, callback) => {
24
24
  break;
25
25
  case 'win32': paths = [
26
26
  ...paths,
27
- path.join(process.env['PROGRAMFILES(X86)'], 'LIBREO~1/program/soffice.exe'),
28
- path.join(process.env['PROGRAMFILES(X86)'], 'LibreOffice/program/soffice.exe'),
29
- path.join(process.env.PROGRAMFILES, 'LibreOffice/program/soffice.exe'),
27
+ path.join(process.env['PROGRAMFILES(X86)'] || '', 'LIBREO~1/program/soffice.exe'),
28
+ path.join(process.env['PROGRAMFILES(X86)'] || '', 'LibreOffice/program/soffice.exe'),
29
+ path.join(process.env.PROGRAMFILES_X86 || '', 'LibreOffice/program/soffice.exe'),
30
+ path.join(process.env.PROGRAMFILES || '', 'LibreOffice/program/soffice.exe'),
31
+ process.env.LIBRE_OFFICE_EXE || '',
32
+ 'C:/Program Files/LibreOffice/program/soffice.exe'
30
33
  ];
31
34
  break;
32
35
  default:
@@ -58,7 +61,12 @@ const convertWithOptions = (document, format, filter, options, callback) => {
58
61
  args.push(tempDir.name);
59
62
  args.push(path.join(tempDir.name, fileName));
60
63
 
61
- return execFile(results.soffice, args, execOptions, callback);
64
+ return execFile(results.soffice, args, execOptions, (err, stdout, stderr) => {
65
+ // warnings might also be emitted to stderr
66
+ if (stderr && stderr.toLowerCase().includes('error'))
67
+ callback(new Error('Error calling soffice: ' + stderr));
68
+ else callback(err, stdout, stderr);
69
+ });
62
70
  }],
63
71
  loadDestination: ['convert', (results, callback) =>
64
72
  async.retry({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libreoffice-convert",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "A simple and fast node.js module for converting office documents to different formats",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -31,4 +31,14 @@ describe('convert', () => {
31
31
  convert(docx, 'txt', undefined, expectHello(done));
32
32
  }, 100);
33
33
  });
34
+
35
+ it('should fail when libreoffice encounters an error', (done) => {
36
+ // call with invalid document: a buffer starting with PNG header but data is missing
37
+ const badPng = Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]);
38
+ convert(badPng, 'txt', undefined, (err, result) => {
39
+ expect(err).toBeInstanceOf(Error);
40
+ expect(err.message).toMatch(/Error calling soffice:/);
41
+ done();
42
+ });
43
+ });
34
44
  });