Skip to content

Commit 592c79d

Browse files
committed
fs: stop destructuring internalBinding fs
1 parent c0c7e86 commit 592c79d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/internal/fs/read/context.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const {
1515

1616
const { Buffer } = require('buffer');
1717

18-
const { FSReqCallback, close, read } = internalBinding('fs');
18+
// It is important to not destructure the binding object, as it will
19+
// cause the creation context to be undefined, and cause fast API calls
20+
// to fail.
21+
const binding = internalBinding('fs');
1922

2023
const {
2124
AbortError,
@@ -102,11 +105,11 @@ class ReadFileContext {
102105
length = MathMin(kReadFileBufferLength, this.size - this.pos);
103106
}
104107

105-
const req = new FSReqCallback();
108+
const req = new binding.FSReqCallback();
106109
req.oncomplete = readFileAfterRead;
107110
req.context = this;
108111

109-
read(this.fd, buffer, offset, length, -1, req);
112+
binding.read(this.fd, buffer, offset, length, -1, req);
110113
}
111114

112115
close(err) {
@@ -117,12 +120,12 @@ class ReadFileContext {
117120
return;
118121
}
119122

120-
const req = new FSReqCallback();
123+
const req = new binding.FSReqCallback();
121124
req.oncomplete = readFileAfterClose;
122125
req.context = this;
123126
this.err = err;
124127

125-
close(this.fd, req);
128+
binding.close(this.fd, req);
126129
}
127130
}
128131

0 commit comments

Comments
 (0)