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

Function ReadStream

lib/internal/fs/streams.js:163–228  ·  view source on GitHub ↗
(path, options)

Source from the content-addressed store, hash-verified

161}
162
163function ReadStream(path, options) {
164 if (!(this instanceof ReadStream))
165 return new ReadStream(path, options);
166
167 // A little bit bigger buffer and water marks by default
168 options = copyObject(getOptions(options, kEmptyObject));
169 if (options.highWaterMark === undefined)
170 options.highWaterMark = 64 * 1024;
171
172 if (options.autoDestroy === undefined) {
173 options.autoDestroy = false;
174 }
175
176 if (options.fd == null) {
177 this.fd = null;
178 this[kFs] = options.fs || fs;
179 validateFunction(this[kFs].open, 'options.fs.open');
180
181 // Path will be ignored when fd is specified, so it can be falsy
182 this.path = toPathIfFileURL(path);
183 this.flags = options.flags === undefined ? 'r' : options.flags;
184 this.mode = options.mode === undefined ? 0o666 : options.mode;
185
186 validatePath(this.path);
187 } else {
188 this.fd = getValidatedFd(importFd(this, options));
189 }
190
191 options.autoDestroy = options.autoClose === undefined ?
192 true : options.autoClose;
193
194 validateFunction(this[kFs].read, 'options.fs.read');
195
196 if (options.autoDestroy) {
197 validateFunction(this[kFs].close, 'options.fs.close');
198 }
199
200 this.start = options.start;
201 this.end = options.end;
202 this.pos = undefined;
203 this.bytesRead = 0;
204 this[kIsPerformingIO] = false;
205
206 if (this.start !== undefined) {
207 validateInteger(this.start, 'start', 0);
208
209 this.pos = this.start;
210 }
211
212
213 if (this.end === undefined) {
214 this.end = Infinity;
215 } else if (this.end !== Infinity) {
216 validateInteger(this.end, 'end', 0);
217
218 if (this.start !== undefined && this.start > this.end) {
219 throw new ERR_OUT_OF_RANGE(
220 'start',

Callers

nothing calls this directly

Calls 4

copyObjectFunction · 0.85
toPathIfFileURLFunction · 0.85
importFdFunction · 0.85
getOptionsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…