|
1 | | -const { existsSync, readFileSync } = require('fs') |
2 | | -const { join } = require('path') |
| 1 | +const { existsSync, readFileSync } = require('fs'); |
| 2 | +const { join } = require('path'); |
3 | 3 |
|
4 | | -const { platform, arch } = process |
| 4 | +const { platform, arch } = process; |
5 | 5 |
|
6 | | -let nativeBinding = null |
7 | | -let localFileExisted = false |
8 | | -let loadError = null |
| 6 | +let nativeBinding = null; |
| 7 | +let localFileExisted = false; |
| 8 | +let loadError = null; |
9 | 9 |
|
10 | 10 | switch (platform) { |
11 | 11 | case 'win32': |
12 | 12 | switch (arch) { |
13 | 13 | case 'x64': |
14 | | - localFileExisted = existsSync( |
15 | | - join(__dirname, 'zstd.win32-x64-msvc.node') |
16 | | - ) |
| 14 | + localFileExisted = existsSync(join(__dirname, 'zstd.win32-x64-msvc.node')); |
17 | 15 | try { |
18 | 16 | if (localFileExisted) { |
19 | | - nativeBinding = require('./zstd.win32-x64-msvc.node') |
| 17 | + nativeBinding = require('./zstd.win32-x64-msvc.node'); |
20 | 18 | } else { |
21 | | - nativeBinding = require('@mongodb-js/zstd-win32-x64-msvc') |
| 19 | + nativeBinding = require('@mongodb-js/zstd-win32-x64-msvc'); |
22 | 20 | } |
23 | 21 | } catch (e) { |
24 | | - loadError = e |
| 22 | + loadError = e; |
25 | 23 | } |
26 | | - break |
| 24 | + break; |
27 | 25 | case 'arm64': |
28 | | - localFileExisted = existsSync( |
29 | | - join(__dirname, 'zstd.win32-arm64-msvc.node') |
30 | | - ) |
| 26 | + localFileExisted = existsSync(join(__dirname, 'zstd.win32-arm64-msvc.node')); |
31 | 27 | try { |
32 | 28 | if (localFileExisted) { |
33 | | - nativeBinding = require('./zstd.win32-arm64-msvc.node') |
| 29 | + nativeBinding = require('./zstd.win32-arm64-msvc.node'); |
34 | 30 | } else { |
35 | | - nativeBinding = require('@mongodb-js/zstd-win32-arm64-msvc') |
| 31 | + nativeBinding = require('@mongodb-js/zstd-win32-arm64-msvc'); |
36 | 32 | } |
37 | 33 | } catch (e) { |
38 | | - loadError = e |
| 34 | + loadError = e; |
39 | 35 | } |
40 | | - break |
| 36 | + break; |
41 | 37 | default: |
42 | | - throw new Error(`Unsupported architecture on Windows: ${arch}`) |
| 38 | + throw new Error(`Unsupported architecture on Windows: ${arch}`); |
43 | 39 | } |
44 | | - break |
| 40 | + break; |
45 | 41 | case 'darwin': |
46 | 42 | switch (arch) { |
47 | 43 | case 'x64': |
48 | | - localFileExisted = existsSync(join(__dirname, 'zstd.darwin-x64.node')) |
| 44 | + localFileExisted = existsSync(join(__dirname, 'zstd.darwin-x64.node')); |
49 | 45 | try { |
50 | 46 | if (localFileExisted) { |
51 | | - nativeBinding = require('./zstd.darwin-x64.node') |
| 47 | + nativeBinding = require('./zstd.darwin-x64.node'); |
52 | 48 | } else { |
53 | | - nativeBinding = require('@mongodb-js/zstd-darwin-x64') |
| 49 | + nativeBinding = require('@mongodb-js/zstd-darwin-x64'); |
54 | 50 | } |
55 | 51 | } catch (e) { |
56 | | - loadError = e |
| 52 | + loadError = e; |
57 | 53 | } |
58 | | - break |
| 54 | + break; |
59 | 55 | case 'arm64': |
60 | | - localFileExisted = existsSync( |
61 | | - join(__dirname, 'zstd.darwin-arm64.node') |
62 | | - ) |
| 56 | + localFileExisted = existsSync(join(__dirname, 'zstd.darwin-arm64.node')); |
63 | 57 | try { |
64 | 58 | if (localFileExisted) { |
65 | | - nativeBinding = require('./zstd.darwin-arm64.node') |
| 59 | + nativeBinding = require('./zstd.darwin-arm64.node'); |
66 | 60 | } else { |
67 | | - nativeBinding = require('@mongodb-js/zstd-darwin-arm64') |
| 61 | + nativeBinding = require('@mongodb-js/zstd-darwin-arm64'); |
68 | 62 | } |
69 | 63 | } catch (e) { |
70 | | - loadError = e |
| 64 | + loadError = e; |
71 | 65 | } |
72 | | - break |
| 66 | + break; |
73 | 67 | default: |
74 | | - throw new Error(`Unsupported architecture on macOS: ${arch}`) |
| 68 | + throw new Error(`Unsupported architecture on macOS: ${arch}`); |
75 | 69 | } |
76 | | - break |
| 70 | + break; |
77 | 71 | case 'freebsd': |
78 | 72 | if (arch !== 'x64') { |
79 | | - throw new Error(`Unsupported architecture on FreeBSD: ${arch}`) |
| 73 | + throw new Error(`Unsupported architecture on FreeBSD: ${arch}`); |
80 | 74 | } |
81 | | - localFileExisted = existsSync(join(__dirname, 'zstd.freebsd-x64.node')) |
| 75 | + localFileExisted = existsSync(join(__dirname, 'zstd.freebsd-x64.node')); |
82 | 76 | try { |
83 | 77 | if (localFileExisted) { |
84 | | - nativeBinding = require('./zstd.freebsd-x64.node') |
| 78 | + nativeBinding = require('./zstd.freebsd-x64.node'); |
85 | 79 | } else { |
86 | | - nativeBinding = require('@mongodb-js/zstd-freebsd-x64') |
| 80 | + nativeBinding = require('@mongodb-js/zstd-freebsd-x64'); |
87 | 81 | } |
88 | 82 | } catch (e) { |
89 | | - loadError = e |
| 83 | + loadError = e; |
90 | 84 | } |
91 | | - break |
| 85 | + break; |
92 | 86 | case 'linux': |
93 | 87 | switch (arch) { |
94 | 88 | case 'x64': |
95 | | - localFileExisted = existsSync( |
96 | | - join(__dirname, 'zstd.linux-x64-gnu.node') |
97 | | - ) |
| 89 | + localFileExisted = existsSync(join(__dirname, 'zstd.linux-x64-gnu.node')); |
98 | 90 | try { |
99 | 91 | if (localFileExisted) { |
100 | | - nativeBinding = require('./zstd.linux-x64-gnu.node') |
| 92 | + nativeBinding = require('./zstd.linux-x64-gnu.node'); |
101 | 93 | } else { |
102 | | - nativeBinding = require('@mongodb-js/zstd-linux-x64-gnu') |
| 94 | + nativeBinding = require('@mongodb-js/zstd-linux-x64-gnu'); |
103 | 95 | } |
104 | 96 | } catch (e) { |
105 | | - loadError = e |
| 97 | + loadError = e; |
106 | 98 | } |
107 | | - break |
| 99 | + break; |
108 | 100 | case 'arm64': |
109 | | - localFileExisted = existsSync( |
110 | | - join(__dirname, 'zstd.linux-arm64-gnu.node') |
111 | | - ) |
| 101 | + localFileExisted = existsSync(join(__dirname, 'zstd.linux-arm64-gnu.node')); |
112 | 102 | try { |
113 | 103 | if (localFileExisted) { |
114 | | - nativeBinding = require('./zstd.linux-arm64-gnu.node') |
| 104 | + nativeBinding = require('./zstd.linux-arm64-gnu.node'); |
115 | 105 | } else { |
116 | | - nativeBinding = require('@mongodb-js/zstd-linux-arm64-gnu') |
| 106 | + nativeBinding = require('@mongodb-js/zstd-linux-arm64-gnu'); |
117 | 107 | } |
118 | 108 | } catch (e) { |
119 | | - loadError = e |
| 109 | + loadError = e; |
120 | 110 | } |
121 | | - break |
| 111 | + break; |
122 | 112 | case 'arm': |
123 | | - localFileExisted = existsSync( |
124 | | - join(__dirname, 'zstd.linux-arm-gnueabihf.node') |
125 | | - ) |
| 113 | + localFileExisted = existsSync(join(__dirname, 'zstd.linux-arm-gnueabihf.node')); |
126 | 114 | try { |
127 | 115 | if (localFileExisted) { |
128 | | - nativeBinding = require('./zstd.linux-arm-gnueabihf.node') |
| 116 | + nativeBinding = require('./zstd.linux-arm-gnueabihf.node'); |
129 | 117 | } else { |
130 | | - nativeBinding = require('@mongodb-js/zstd-linux-arm-gnueabihf') |
| 118 | + nativeBinding = require('@mongodb-js/zstd-linux-arm-gnueabihf'); |
131 | 119 | } |
132 | 120 | } catch (e) { |
133 | | - loadError = e |
| 121 | + loadError = e; |
134 | 122 | } |
135 | | - break |
| 123 | + break; |
136 | 124 | default: |
137 | | - throw new Error(`Unsupported architecture on Linux: ${arch}`) |
| 125 | + throw new Error(`Unsupported architecture on Linux: ${arch}`); |
138 | 126 | } |
139 | | - break |
| 127 | + break; |
140 | 128 | default: |
141 | | - throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) |
| 129 | + throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`); |
142 | 130 | } |
143 | 131 |
|
144 | 132 | if (!nativeBinding) { |
145 | 133 | if (loadError) { |
146 | | - throw loadError |
| 134 | + throw loadError; |
147 | 135 | } |
148 | | - throw new Error(`Failed to load native binding`) |
| 136 | + throw new Error(`Failed to load native binding`); |
149 | 137 | } |
150 | 138 |
|
151 | | -const { compress, decompress } = nativeBinding |
| 139 | +const { compress, decompress } = nativeBinding; |
152 | 140 |
|
153 | | -module.exports.compress = compress |
154 | | -module.exports.decompress = decompress |
| 141 | +module.exports.compress = compress; |
| 142 | +module.exports.decompress = decompress; |
0 commit comments