xhs-mp-shared-fs 2.0.15-beta.2 → 2.0.16

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.
Files changed (2) hide show
  1. package/lib/shared-fs.js +22 -19
  2. package/package.json +1 -1
package/lib/shared-fs.js CHANGED
@@ -1,6 +1,9 @@
1
1
  const addonPath = process.platform === 'win32' ? './shared_fs_win.node' : `./shared_fs_mac_${process.arch}.node`
2
- const addon = require(addonPath)
3
2
  const stream = require('readable-stream')
3
+ const getLazyAddon = () => {
4
+ const addon = require(addonPath)
5
+ return addon
6
+ }
4
7
 
5
8
  const ReadableStream = stream.Readable
6
9
  const WritableStream = stream.Writable
@@ -8,56 +11,56 @@ const WritableStream = stream.Writable
8
11
  class SharedFs {
9
12
 
10
13
  existsSync(_path) {
11
- return addon.existsSync(_path)
14
+ return getLazyAddon().existsSync(_path)
12
15
  }
13
16
 
14
17
  exists(_path, callback) {
15
- return addon.exists(_path, callback)
18
+ return getLazyAddon().exists(_path, callback)
16
19
  }
17
20
 
18
21
  statSync(_path) {
19
- const stats = addon.statSync(_path)
22
+ const stats = getLazyAddon().statSync(_path)
20
23
  return stats
21
24
  }
22
25
 
23
26
  stat(_path, callback) {
24
- addon.stat(_path, callback)
27
+ getLazyAddon().stat(_path, callback)
25
28
  }
26
29
 
27
30
  lstat(_path, callback) {
28
- addon.lstat(_path, callback)
31
+ getLazyAddon().lstat(_path, callback)
29
32
  }
30
33
 
31
34
  mkdir(_path, callback) {
32
- addon.mkdir(_path, callback)
35
+ getLazyAddon().mkdir(_path, callback)
33
36
  }
34
37
 
35
38
  mkdirSync(_path) {
36
- return addon.mkdirSync(_path)
39
+ return getLazyAddon().mkdirSync(_path)
37
40
  }
38
41
 
39
42
  rmdir(_path, callback) {
40
- addon.rmdir(_path, callback)
43
+ getLazyAddon().rmdir(_path, callback)
41
44
  }
42
45
 
43
46
  rmdirSync(_path) {
44
- return addon.rmdirSync(_path)
47
+ return getLazyAddon().rmdirSync(_path)
45
48
  }
46
49
 
47
50
  readdir(_path, callback) {
48
- return addon.readdir(_path, callback)
51
+ return getLazyAddon().readdir(_path, callback)
49
52
  }
50
53
 
51
54
  unlinkSync(_path) {
52
- return addon.unlinkSync(_path)
55
+ return getLazyAddon().unlinkSync(_path)
53
56
  }
54
57
 
55
58
  unlink(_path, callback) {
56
- return addon.unlink(_path, callback)
59
+ return getLazyAddon().unlink(_path, callback)
57
60
  }
58
61
 
59
62
  readFileSync(_path, optionsOrEncoding) {
60
- const buffer = addon.readFileSync(_path)
63
+ const buffer = getLazyAddon().readFileSync(_path)
61
64
  const encoding = typeof optionsOrEncoding === 'object' ? optionsOrEncoding.encoding : optionsOrEncoding
62
65
  return encoding ? buffer.toString(encoding) : buffer
63
66
  }
@@ -67,7 +70,7 @@ class SharedFs {
67
70
  callback = optArg
68
71
  optArg = undefined
69
72
  }
70
- addon.readFile(_path, (err, buffer) => {
73
+ getLazyAddon().readFile(_path, (err, buffer) => {
71
74
  if (err) {
72
75
  callback(err)
73
76
  return
@@ -84,7 +87,7 @@ class SharedFs {
84
87
  if (!content && !optionsOrEncoding) throw new Error('No content')
85
88
  const encoding = typeof optionsOrEncoding === 'object' ? optionsOrEncoding.encoding : optionsOrEncoding
86
89
  const buffer = optionsOrEncoding || typeof content === 'string' ? new Buffer(content, encoding) : content
87
- addon.writeFileSync(_path, buffer)
90
+ getLazyAddon().writeFileSync(_path, buffer)
88
91
  }
89
92
 
90
93
  writeFile(path, content, encoding, callback) {
@@ -93,7 +96,7 @@ class SharedFs {
93
96
  encoding = undefined
94
97
  }
95
98
  const buffer = encoding || typeof content === 'string' ? new Buffer(content, encoding) : content
96
- addon.writeFile(path, buffer, callback)
99
+ getLazyAddon().writeFile(path, buffer, callback)
97
100
  }
98
101
 
99
102
  // stream methods
@@ -151,11 +154,11 @@ class SharedFs {
151
154
  }
152
155
 
153
156
  clear() {
154
- addon.clear()
157
+ getLazyAddon().clear()
155
158
  }
156
159
 
157
160
  print() {
158
- addon.print()
161
+ getLazyAddon().print()
159
162
  }
160
163
  }
161
164
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-shared-fs",
3
- "version": "2.0.15-beta.2",
3
+ "version": "2.0.16",
4
4
  "description": "跨线程共享fs",
5
5
  "main": "lib/index.js",
6
6
  "gypfile": true,