bare-fs 4.2.3 → 4.3.1

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.
@@ -0,0 +1,11 @@
1
+ declare class FileError extends Error {
2
+ private constructor(msg: string)
3
+
4
+ readonly code: string
5
+ readonly operation?: string
6
+ readonly path?: string
7
+ readonly destination?: string
8
+ readonly fd?: number
9
+ }
10
+
11
+ export = FileError
package/lib/errors.js ADDED
@@ -0,0 +1,61 @@
1
+ const os = require('bare-os')
2
+
3
+ module.exports = class FileError extends Error {
4
+ constructor(msg, opts = {}) {
5
+ const {
6
+ code,
7
+ operation = null,
8
+ path = null,
9
+ destination = null,
10
+ fd = -1
11
+ } = opts
12
+
13
+ if (operation !== null) msg += describe(operation, opts)
14
+
15
+ super(`${code}: ${msg}`)
16
+
17
+ this.code = code
18
+
19
+ if (operation !== null) this.operation = operation
20
+ if (path !== null) this.path = path
21
+ if (destination !== null) this.destination = destination
22
+ if (fd !== -1) this.fd = fd
23
+ }
24
+
25
+ get name() {
26
+ return 'FileError'
27
+ }
28
+
29
+ // For Node.js compatibility
30
+ get errno() {
31
+ return os.constants.errnos[this.code]
32
+ }
33
+
34
+ // For Node.js compatibility
35
+ get syscall() {
36
+ return this.operation
37
+ }
38
+
39
+ // For Node.js compatibility
40
+ get dest() {
41
+ return this.destination
42
+ }
43
+ }
44
+
45
+ function describe(operation, opts) {
46
+ const { path = null, destination = null, fd = -1 } = opts
47
+
48
+ let result = `, ${operation}`
49
+
50
+ if (path !== null) {
51
+ result += ` ${JSON.stringify(path)}`
52
+
53
+ if (destination !== null) {
54
+ result += ` -> ${JSON.stringify(destination)}`
55
+ }
56
+ } else if (fd !== -1) {
57
+ result += ` ${fd}`
58
+ }
59
+
60
+ return result
61
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bare-fs",
3
- "version": "4.2.3",
4
- "description": "Native file system for Javascript",
3
+ "version": "4.3.1",
4
+ "description": "Native file system operations for Javascript",
5
5
  "exports": {
6
6
  "./package": "./package.json",
7
7
  ".": {
@@ -48,7 +48,8 @@
48
48
  "dependencies": {
49
49
  "bare-events": "^2.5.4",
50
50
  "bare-path": "^3.0.0",
51
- "bare-stream": "^2.6.4"
51
+ "bare-stream": "^2.6.4",
52
+ "bare-url": "^2.2.2"
52
53
  },
53
54
  "devDependencies": {
54
55
  "bare-buffer": "^3.0.2",
@@ -58,11 +59,15 @@
58
59
  "prettier-config-standard": "^7.0.0"
59
60
  },
60
61
  "peerDependencies": {
61
- "bare-buffer": "*"
62
+ "bare-buffer": "*",
63
+ "bare-url": "*"
62
64
  },
63
65
  "peerDependenciesMeta": {
64
66
  "bare-buffer": {
65
67
  "optional": true
68
+ },
69
+ "bare-url": {
70
+ "optional": true
66
71
  }
67
72
  }
68
73
  }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/promises.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import Buffer, { BufferEncoding } from 'bare-buffer'
2
- import fs, {
2
+ import {
3
3
  AppendFileOptions,
4
4
  Dir,
5
5
  MkdirOptions,
6
6
  OpendirOptions,
7
+ Path,
7
8
  ReadFileOptions,
8
9
  ReaddirOptions,
9
10
  ReadlinkOptions,
@@ -15,255 +16,252 @@ import fs, {
15
16
  WriteFileOptions
16
17
  } from '.'
17
18
 
18
- export function access(filepath: string, mode?: number): Promise<void>
19
+ export function access(filepath: Path, mode?: number): Promise<void>
19
20
 
20
21
  export function appendFile(
21
- filepath: string,
22
+ filepath: Path,
22
23
  data: string | Buffer | ArrayBufferView,
23
24
  opts?: AppendFileOptions
24
25
  ): Promise<void>
25
26
 
26
27
  export function appendFile(
27
- filepath: string,
28
+ filepath: Path,
28
29
  data: string | Buffer | ArrayBufferView,
29
30
  encoding: BufferEncoding
30
31
  ): Promise<void>
31
32
 
32
- export function chmod(filepath: string, mode: string | number): Promise<void>
33
+ export function chmod(filepath: Path, mode: string | number): Promise<void>
33
34
 
34
- export function copyFile(src: string, dst: string, mode?: number): Promise<void>
35
+ export function copyFile(src: Path, dst: Path, mode?: number): Promise<void>
35
36
 
36
- export function lstat(filepath: string): Promise<Stats>
37
+ export function lstat(filepath: Path): Promise<Stats>
37
38
 
38
- export function mkdir(filepath: string, opts?: MkdirOptions): Promise<void>
39
+ export function mkdir(filepath: Path, opts?: MkdirOptions): Promise<void>
39
40
 
40
- export function mkdir(filepath: string, mode: number): Promise<void>
41
+ export function mkdir(filepath: Path, mode: number): Promise<void>
41
42
 
42
43
  export function opendir(
43
- filepath: string,
44
+ filepath: Path,
44
45
  opts: OpendirOptions & { encoding?: BufferEncoding }
45
46
  ): Promise<Dir<string>>
46
47
 
47
48
  export function opendir(
48
- filepath: string,
49
+ filepath: Path,
49
50
  opts: OpendirOptions & { encoding: 'buffer' }
50
51
  ): Promise<Dir<Buffer>>
51
52
 
52
- export function opendir(filepath: string, opts: OpendirOptions): Promise<Dir>
53
+ export function opendir(filepath: Path, opts: OpendirOptions): Promise<Dir>
53
54
 
54
55
  export function opendir(
55
- filepath: string,
56
+ filepath: Path,
56
57
  encoding: BufferEncoding
57
58
  ): Promise<Dir<string>>
58
59
 
59
60
  export function opendir(
60
- filepath: string,
61
+ filepath: Path,
61
62
  encoding: 'buffer'
62
63
  ): Promise<Dir<Buffer>>
63
64
 
64
65
  export function opendir(
65
- filepath: string,
66
+ filepath: Path,
66
67
  encoding: BufferEncoding | 'buffer'
67
68
  ): Promise<Dir>
68
69
 
69
- export function opendir(filepath: string): Promise<Dir<string>>
70
+ export function opendir(filepath: Path): Promise<Dir<string>>
70
71
 
71
72
  export function readFile(
72
- filepath: string,
73
+ filepath: Path,
73
74
  opts: ReadFileOptions & { encoding: BufferEncoding }
74
75
  ): Promise<string>
75
76
 
76
77
  export function readFile(
77
- filepath: string,
78
+ filepath: Path,
78
79
  opts: ReadFileOptions & { encoding?: 'buffer' }
79
80
  ): Promise<Buffer>
80
81
 
81
82
  export function readFile(
82
- filepath: string,
83
+ filepath: Path,
83
84
  opts: ReadFileOptions
84
85
  ): Promise<string | Buffer>
85
86
 
86
87
  export function readFile(
87
- filepath: string,
88
+ filepath: Path,
88
89
  encoding: BufferEncoding
89
90
  ): Promise<string>
90
91
 
91
- export function readFile(filepath: string, encoding: 'buffer'): Promise<Buffer>
92
+ export function readFile(filepath: Path, encoding: 'buffer'): Promise<Buffer>
92
93
 
93
94
  export function readFile(
94
- filepath: string,
95
+ filepath: Path,
95
96
  encoding?: BufferEncoding | 'buffer'
96
97
  ): Promise<string | Buffer>
97
98
 
98
- export function readFile(filepath: string): Promise<Buffer>
99
+ export function readFile(filepath: Path): Promise<Buffer>
99
100
 
100
101
  export function readdir(
101
- filepath: string,
102
+ filepath: Path,
102
103
  opts: ReaddirOptions & { encoding?: BufferEncoding }
103
104
  ): Promise<Dir<string>[] | string[]>
104
105
 
105
106
  export function readdir(
106
- filepath: string,
107
+ filepath: Path,
107
108
  opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes: true }
108
109
  ): Promise<Dir<string>[]>
109
110
 
110
111
  export function readdir(
111
- filepath: string,
112
+ filepath: Path,
112
113
  opts: ReaddirOptions & { encoding?: BufferEncoding; withFileTypes?: false }
113
114
  ): Promise<string[]>
114
115
 
115
116
  export function readdir(
116
- filepath: string,
117
+ filepath: Path,
117
118
  opts: ReaddirOptions & { encoding: 'buffer' }
118
119
  ): Promise<Dir<Buffer>[] | Buffer[]>
119
120
 
120
121
  export function readdir(
121
- filepath: string,
122
+ filepath: Path,
122
123
  opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes: true }
123
124
  ): Promise<Dir<Buffer>[]>
124
125
 
125
126
  export function readdir(
126
- filepath: string,
127
+ filepath: Path,
127
128
  opts: ReaddirOptions & { encoding: 'buffer'; withFileTypes?: false }
128
129
  ): Promise<Buffer[]>
129
130
 
130
131
  export function readdir(
131
- filepath: string,
132
+ filepath: Path,
132
133
  opts: ReaddirOptions & { withFileTypes: true }
133
134
  ): Promise<Dir<string | Buffer>[]>
134
135
 
135
136
  export function readdir(
136
- filepath: string,
137
+ filepath: Path,
137
138
  opts: ReaddirOptions & { withFileTypes?: false }
138
139
  ): Promise<string[] | Buffer[]>
139
140
 
140
141
  export function readdir(
141
- filepath: string,
142
+ filepath: Path,
142
143
  opts: ReaddirOptions
143
144
  ): Promise<Dir[] | string[] | Buffer[]>
144
145
 
145
146
  export function readdir(
146
- filepath: string,
147
+ filepath: Path,
147
148
  encoding: BufferEncoding
148
149
  ): Promise<string[]>
149
150
 
150
- export function readdir(filepath: string, encoding: 'buffer'): Promise<Buffer[]>
151
+ export function readdir(filepath: Path, encoding: 'buffer'): Promise<Buffer[]>
151
152
 
152
153
  export function readdir(
153
- filepath: string,
154
+ filepath: Path,
154
155
  encoding: BufferEncoding | 'buffer'
155
156
  ): Promise<string[] | Buffer[]>
156
157
 
157
- export function readdir(filepath: string): Promise<string[]>
158
+ export function readdir(filepath: Path): Promise<string[]>
158
159
 
159
160
  export function readlink(
160
- filepath: string,
161
+ filepath: Path,
161
162
  opts: ReadlinkOptions & { encoding?: BufferEncoding }
162
163
  ): Promise<string>
163
164
 
164
165
  export function readlink(
165
- filepath: string,
166
+ filepath: Path,
166
167
  opts: ReadlinkOptions & { encoding: 'buffer' }
167
168
  ): Promise<Buffer>
168
169
 
169
170
  export function readlink(
170
- filepath: string,
171
+ filepath: Path,
171
172
  opts: ReadlinkOptions
172
173
  ): Promise<string | Buffer>
173
174
 
174
175
  export function readlink(
175
- filepath: string,
176
+ filepath: Path,
176
177
  encoding: BufferEncoding
177
178
  ): Promise<string>
178
179
 
179
- export function readlink(filepath: string, encoding: 'buffer'): Promise<Buffer>
180
+ export function readlink(filepath: Path, encoding: 'buffer'): Promise<Buffer>
180
181
 
181
182
  export function readlink(
182
- filepath: string,
183
+ filepath: Path,
183
184
  encoding: BufferEncoding | 'buffer'
184
185
  ): Promise<string | Buffer>
185
186
 
186
- export function readlink(filepath: string): Promise<string>
187
+ export function readlink(filepath: Path): Promise<string>
187
188
 
188
189
  export function realpath(
189
- filepath: string,
190
+ filepath: Path,
190
191
  opts: RealpathOptions & { encoding?: BufferEncoding }
191
192
  ): Promise<string>
192
193
 
193
194
  export function realpath(
194
- filepath: string,
195
+ filepath: Path,
195
196
  opts: RealpathOptions & { encoding: 'buffer' }
196
197
  ): Promise<Buffer>
197
198
 
198
199
  export function realpath(
199
- filepath: string,
200
+ filepath: Path,
200
201
  opts: RealpathOptions
201
202
  ): Promise<string | Buffer>
202
203
 
203
204
  export function realpath(
204
- filepath: string,
205
+ filepath: Path,
205
206
  encoding: BufferEncoding
206
207
  ): Promise<string>
207
208
 
208
- export function realpath(filepath: string, encoding: 'buffer'): Promise<Buffer>
209
+ export function realpath(filepath: Path, encoding: 'buffer'): Promise<Buffer>
209
210
 
210
211
  export function realpath(
211
- filepath: string,
212
+ filepath: Path,
212
213
  encoding: BufferEncoding | 'buffer'
213
214
  ): Promise<string | Buffer>
214
215
 
215
- export function realpath(filepath: string): Promise<string>
216
+ export function realpath(filepath: Path): Promise<string>
216
217
 
217
- export function rename(src: string, dst: string): Promise<void>
218
+ export function rename(src: Path, dst: Path): Promise<void>
218
219
 
219
- export function rm(filepath: string, opts?: RmOptions): Promise<void>
220
+ export function rm(filepath: Path, opts?: RmOptions): Promise<void>
220
221
 
221
- export function rmdir(filepath: string): Promise<void>
222
+ export function rmdir(filepath: Path): Promise<void>
222
223
 
223
- export function stat(filepath: string): Promise<Stats>
224
+ export function stat(filepath: Path): Promise<Stats>
224
225
 
225
226
  export function symlink(
226
- target: string,
227
- filepath: string,
227
+ target: Path,
228
+ filepath: Path,
228
229
  type?: string | number
229
230
  ): Promise<void>
230
231
 
231
- export function unlink(filepath: string): Promise<void>
232
+ export function unlink(filepath: Path): Promise<void>
232
233
 
233
234
  export function watch(
234
- filepath: string,
235
+ filepath: Path,
235
236
  opts: WatcherOptions & { encoding?: BufferEncoding }
236
237
  ): Watcher<string>
237
238
 
238
239
  export function watch(
239
- filepath: string,
240
+ filepath: Path,
240
241
  opts: WatcherOptions & { encoding: 'buffer' }
241
242
  ): Watcher<Buffer>
242
243
 
243
- export function watch(filepath: string, opts: WatcherOptions): Watcher
244
+ export function watch(filepath: Path, opts: WatcherOptions): Watcher
244
245
 
245
- export function watch(
246
- filepath: string,
247
- encoding: BufferEncoding
248
- ): Watcher<string>
246
+ export function watch(filepath: Path, encoding: BufferEncoding): Watcher<string>
249
247
 
250
- export function watch(filepath: string, encoding: 'buffer'): Watcher<Buffer>
248
+ export function watch(filepath: Path, encoding: 'buffer'): Watcher<Buffer>
251
249
 
252
250
  export function watch(
253
- filepath: string,
251
+ filepath: Path,
254
252
  encoding: BufferEncoding | 'buffer'
255
253
  ): Watcher
256
254
 
257
- export function watch(filepath: string): Watcher<string>
255
+ export function watch(filepath: Path): Watcher<string>
258
256
 
259
257
  export function writeFile(
260
- filepath: string,
258
+ filepath: Path,
261
259
  data: string | Buffer | ArrayBufferView,
262
260
  opts?: WriteFileOptions
263
261
  ): Promise<void>
264
262
 
265
263
  export function writeFile(
266
- filepath: string,
264
+ filepath: Path,
267
265
  data: string | Buffer | ArrayBufferView,
268
266
  encoding: BufferEncoding
269
267
  ): Promise<void>
package/promises.js CHANGED
@@ -1 +1,22 @@
1
- module.exports = require('.').promises
1
+ const fs = require('.')
2
+
3
+ exports.access = fs.access
4
+ exports.appendFile = fs.appendFile
5
+ exports.chmod = fs.chmod
6
+ exports.copyFile = fs.copyFile
7
+ exports.lstat = fs.lstat
8
+ exports.mkdir = fs.mkdir
9
+ exports.opendir = fs.opendir
10
+ exports.readFile = fs.readFile
11
+ exports.readdir = fs.readdir
12
+ exports.readlink = fs.readlink
13
+ exports.realpath = fs.realpath
14
+ exports.rename = fs.rename
15
+ exports.rm = fs.rm
16
+ exports.rmdir = fs.rmdir
17
+ exports.stat = fs.stat
18
+ exports.symlink = fs.symlink
19
+ exports.unlink = fs.unlink
20
+ exports.utimes = fs.utimes
21
+ exports.writeFile = fs.writeFile
22
+ exports.watch = fs.watch