frida-fs 4.0.2 → 5.0.2

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/index.js +32 -30
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {Buffer} from 'buffer';
2
+ import process from 'process';
2
3
  import stream from 'stream';
3
4
 
4
5
  const {platform, pointerSize} = Process;
@@ -100,14 +101,24 @@ class ReadStream extends stream.Readable {
100
101
  const pathStr = Memory.allocUtf8String(path);
101
102
  const fd = getApi().open(pathStr, constants.O_RDONLY, 0);
102
103
  if (fd.value === -1) {
103
- this.emit('error', new Error(`Unable to open file (${getErrorString(fd.errno)})`));
104
- this.push(null);
104
+ process.nextTick(() => {
105
+ this.destroy(new Error(getErrorString(fd.errno)));
106
+ });
105
107
  return;
106
108
  }
107
109
 
108
110
  this._input = new UnixInputStream(fd.value, { autoClose: true });
109
111
  }
110
112
 
113
+ _destroy(err, callback) {
114
+ if (this._input !== null) {
115
+ this._input.close();
116
+ this._input = null;
117
+ }
118
+
119
+ callback(err);
120
+ }
121
+
111
122
  _read(size) {
112
123
  if (this._readRequest !== null)
113
124
  return;
@@ -117,7 +128,6 @@ class ReadStream extends stream.Readable {
117
128
  this._readRequest = null;
118
129
 
119
130
  if (buffer.byteLength === 0) {
120
- this._closeInput();
121
131
  this.push(null);
122
132
  return;
123
133
  }
@@ -127,18 +137,9 @@ class ReadStream extends stream.Readable {
127
137
  })
128
138
  .catch(error => {
129
139
  this._readRequest = null;
130
- this._closeInput();
131
- this.emit('error', error);
132
- this.push(null);
140
+ this.destroy(error);
133
141
  });
134
142
  }
135
-
136
- _closeInput() {
137
- if (this._input !== null) {
138
- this._input.close();
139
- this._input = null;
140
- }
141
- }
142
143
  }
143
144
 
144
145
  class WriteStream extends stream.Writable {
@@ -155,14 +156,22 @@ class WriteStream extends stream.Writable {
155
156
  const mode = constants.S_IRUSR | constants.S_IWUSR | constants.S_IRGRP | constants.S_IROTH;
156
157
  const fd = getApi().open(pathStr, flags, mode);
157
158
  if (fd.value === -1) {
158
- this.emit('error', new Error(`Unable to open file (${getErrorString(fd.errno)})`));
159
- this.push(null);
159
+ process.nextTick(() => {
160
+ this.destroy(new Error(getErrorString(fd.errno)));
161
+ });
160
162
  return;
161
163
  }
162
164
 
163
165
  this._output = new UnixOutputStream(fd.value, { autoClose: true });
164
- this.on('finish', () => this._closeOutput());
165
- this.on('error', () => this._closeOutput());
166
+ }
167
+
168
+ _destroy(err, callback) {
169
+ if (this._output !== null) {
170
+ this._output.close();
171
+ this._output = null;
172
+ }
173
+
174
+ callback(err);
166
175
  }
167
176
 
168
177
  _write(chunk, encoding, callback) {
@@ -181,13 +190,6 @@ class WriteStream extends stream.Writable {
181
190
  callback(error);
182
191
  });
183
192
  }
184
-
185
- _closeOutput() {
186
- if (this._output !== null) {
187
- this._output.close();
188
- this._output = null;
189
- }
190
- }
191
193
  }
192
194
 
193
195
  const direntSpecs = {
@@ -240,7 +242,7 @@ function enumerateDirectoryEntries(path, callback) {
240
242
  const dir = opendirImpl(Memory.allocUtf8String(path));
241
243
  const dirHandle = dir.value;
242
244
  if (dirHandle.isNull())
243
- throw new Error(`Unable to open directory (${getErrorString(dir.errno)})`);
245
+ throw new Error(getErrorString(dir.errno));
244
246
 
245
247
  try {
246
248
  let entry;
@@ -275,7 +277,7 @@ function readFileSync(path, options = {}) {
275
277
  const openResult = open(pathStr, constants.O_RDONLY, 0);
276
278
  const fd = openResult.value;
277
279
  if (fd === -1)
278
- throw new Error(`Unable to open file (${getErrorString(openResult.errno)})`);
280
+ throw new Error(getErrorString(openResult.errno));
279
281
 
280
282
  try {
281
283
  const fileSize = lseek(fd, 0, SEEK_END).valueOf();
@@ -291,7 +293,7 @@ function readFileSync(path, options = {}) {
291
293
  } while (readFailed && readResult.errno === EINTR);
292
294
 
293
295
  if (readFailed)
294
- throw new Error(`Unable to read ${path} (${getErrorString(readResult.errno)})`);
296
+ throw new Error(getErrorString(readResult.errno));
295
297
 
296
298
  if (n !== fileSize.valueOf())
297
299
  throw new Error('Short read');
@@ -322,7 +324,7 @@ function readlinkSync(path) {
322
324
  const result = api.readlink(pathStr, buf, linkSize);
323
325
  const n = result.value.valueOf();
324
326
  if (n === -1)
325
- throw new Error(`Unable to read link (${getErrorString(result.errno)})`);
327
+ throw new Error(getErrorString(result.errno));
326
328
 
327
329
  return buf.readUtf8String(n);
328
330
  }
@@ -334,7 +336,7 @@ function unlinkSync(path) {
334
336
 
335
337
  const result = unlink(pathStr);
336
338
  if (result.value === -1)
337
- throw new Error(`Unable to unlink (${getErrorString(result.errno)})`);
339
+ throw new Error(getErrorString(result.errno));
338
340
  }
339
341
 
340
342
  const statFields = new Set([
@@ -521,7 +523,7 @@ function performStat(impl, path) {
521
523
  const buf = Memory.alloc(statBufSize);
522
524
  const result = impl(Memory.allocUtf8String(path), buf);
523
525
  if (result.value !== 0)
524
- throw new Error(`Unable to stat ${path} (${getErrorString(result.errno)})`);
526
+ throw new Error(getErrorString(result.errno));
525
527
 
526
528
  return new Proxy(new Stats(), {
527
529
  has(target, property) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frida-fs",
3
- "version": "4.0.2",
3
+ "version": "5.0.2",
4
4
  "description": "Create a stream from a filesystem resource",
5
5
  "main": "index.js",
6
6
  "type": "module",