MCPcopy Index your code
hub / github.com/nodejs/node / importFd

Function importFd

lib/internal/fs/streams.js:137–161  ·  view source on GitHub ↗
(stream, options)

Source from the content-addressed store, hash-verified

135}
136
137function importFd(stream, options) {
138 if (typeof options.fd === 'number') {
139 // When fd is a raw descriptor, we must keep our fingers crossed
140 // that the descriptor won't get closed, or worse, replaced with
141 // another one
142 // https://github.com/nodejs/node/issues/35862
143 stream[kFs] = options.fs || fs;
144 return options.fd;
145 } else if (typeof options.fd === 'object' &&
146 options.fd instanceof FileHandle) {
147 // When fd is a FileHandle we can listen for 'close' events
148 if (options.fs) {
149 // FileHandle is not supported with custom fs operations
150 throw new ERR_METHOD_NOT_IMPLEMENTED('FileHandle with fs');
151 }
152 stream[kHandle] = options.fd;
153 stream[kFs] = FileHandleOperations(stream[kHandle]);
154 stream[kHandle][kRef]();
155 options.fd.on('close', FunctionPrototypeBind(stream.close, stream));
156 return options.fd.fd;
157 }
158
159 throw new ERR_INVALID_ARG_TYPE('options.fd',
160 ['number', 'FileHandle'], options.fd);
161}
162
163function ReadStream(path, options) {
164 if (!(this instanceof ReadStream))

Callers 2

ReadStreamFunction · 0.85
WriteStreamFunction · 0.85

Calls 2

FileHandleOperationsFunction · 0.85
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…