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

Function read

lib/fs.js:747–830  ·  view source on GitHub ↗

* Reads file from the specified `fd` (file descriptor). * @param {number} fd * @param {Buffer | TypedArray | DataView} buffer * @param {number | { * offset?: number; * length?: number; * position?: number | bigint | null; * }} [offsetOrOptions] * @param {number} length * @param {num

(fd, buffer, offsetOrOptions, length, position, callback)

Source from the content-addressed store, hash-verified

745 * @returns {void}
746 */
747function read(fd, buffer, offsetOrOptions, length, position, callback) {
748 fd = getValidatedFd(fd);
749 let offset = offsetOrOptions;
750 let params = null;
751 if (arguments.length <= 4) {
752 if (arguments.length === 4) {
753 // This is fs.read(fd, buffer, options, callback)
754 validateObject(offsetOrOptions, 'options', kValidateObjectAllowNullable);
755 callback = length;
756 params = offsetOrOptions;
757 } else if (arguments.length === 3) {
758 // This is fs.read(fd, bufferOrParams, callback)
759 if (!isArrayBufferView(buffer)) {
760 // This is fs.read(fd, params, callback)
761 params = buffer;
762 ({ buffer = Buffer.alloc(16384) } = params ?? kEmptyObject);
763 }
764 callback = offsetOrOptions;
765 } else {
766 // This is fs.read(fd, callback)
767 callback = buffer;
768 buffer = Buffer.alloc(16384);
769 }
770
771 if (params !== undefined) {
772 validateObject(params, 'options', kValidateObjectAllowNullable);
773 }
774 ({
775 offset = 0,
776 length = buffer?.byteLength - offset,
777 position = null,
778 } = params ?? kEmptyObject);
779 }
780
781 validateBuffer(buffer);
782 validateFunction(callback, 'cb');
783
784 if (offset == null) {
785 offset = 0;
786 } else {
787 validateInteger(offset, 'offset', 0);
788 }
789
790 length |= 0;
791
792 if (position == null) {
793 position = -1;
794 } else {
795 validatePosition(position, 'position', length);
796 }
797
798 if (length === 0) {
799 return process.nextTick(function tick() {
800 callback(null, 0, buffer);
801 });
802 }
803
804 if (buffer.byteLength === 0) {

Callers 2

readdirRecursiveFunction · 0.70
readdirSyncRecursiveFunction · 0.70

Calls 5

processReaddirResultFunction · 0.85
allocMethod · 0.80
callbackFunction · 0.50
readMethod · 0.45
readdirMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…