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

Function readSync

lib/fs.js:849–897  ·  view source on GitHub ↗

* Synchronously reads the 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}

(fd, buffer, offsetOrOptions, length, position)

Source from the content-addressed store, hash-verified

847 * @returns {number}
848 */
849function readSync(fd, buffer, offsetOrOptions, length, position) {
850 validateBuffer(buffer);
851
852 let offset = offsetOrOptions;
853 if (arguments.length <= 3 || typeof offsetOrOptions === 'object') {
854 if (offsetOrOptions !== undefined) {
855 validateObject(offsetOrOptions, 'options', kValidateObjectAllowNullable);
856 }
857
858 ({
859 offset = 0,
860 length = buffer.byteLength - offset,
861 position = null,
862 } = offsetOrOptions ?? kEmptyObject);
863 }
864
865 if (offset === undefined) {
866 offset = 0;
867 } else {
868 validateInteger(offset, 'offset', 0);
869 }
870
871 length |= 0;
872
873 if (position == null) {
874 position = -1;
875 } else {
876 validatePosition(position, 'position', length);
877 }
878
879 if (length === 0) {
880 return 0;
881 }
882
883 if (buffer.byteLength === 0) {
884 throw new ERR_INVALID_ARG_VALUE('buffer', buffer,
885 'is empty and cannot be written');
886 }
887
888 validateOffsetLengthRead(offset, length, buffer.byteLength);
889
890 const h = vfsState.handlers;
891 if (h !== null) {
892 const result = h.readSync(fd, buffer, offset, length, position);
893 if (result !== undefined) return result;
894 }
895
896 return binding.read(fd, buffer, offset, length, position);
897}
898
899/**
900 * Reads file from the specified `fd` (file descriptor)

Callers 1

Calls 2

readSyncMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…