Permalink
Browse files

Revert "fs: ensure readFile[Sync] reads from the beginning"

This reverts commit 4444e73.

PR-URL: #10809
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information...
thefourtheye authored and addaleax committed Jan 14, 2017
1 parent 4444e73 commit 66f09be74399b61a433a58dfe48c6fd5b9d66594
Showing with 5 additions and 28 deletions.
  1. +5 −5 lib/fs.js
  2. +0 −23 test/parallel/test-fs-readfile-fd-offset.js
@@ -310,7 +310,7 @@ ReadFileContext.prototype.read = function() {
req.oncomplete = readFileAfterRead;
req.context = this;
binding.read(this.fd, buffer, offset, length, this.pos, req);
binding.read(this.fd, buffer, offset, length, -1, req);
};
ReadFileContext.prototype.close = function(err) {
@@ -447,11 +447,11 @@ function tryCreateBuffer(size, fd, isUserFd) {
return buffer;
}
function tryReadSync(fd, isUserFd, buffer, pos, len, offset) {
function tryReadSync(fd, isUserFd, buffer, pos, len) {
var threw = true;
var bytesRead;
try {
bytesRead = fs.readSync(fd, buffer, pos, len, offset);
bytesRead = fs.readSync(fd, buffer, pos, len);
threw = false;
} finally {
if (threw && !isUserFd) fs.closeSync(fd);
@@ -480,15 +480,15 @@ fs.readFileSync = function(path, options) {
if (size !== 0) {
do {
bytesRead = tryReadSync(fd, isUserFd, buffer, pos, size - pos, pos);
bytesRead = tryReadSync(fd, isUserFd, buffer, pos, size - pos);
pos += bytesRead;
} while (bytesRead !== 0 && pos < size);
} else {
do {
// the kernel lies about many files.
// Go ahead and try to read some bytes.
buffer = Buffer.allocUnsafe(8192);
bytesRead = tryReadSync(fd, isUserFd, buffer, 0, 8192, pos);
bytesRead = tryReadSync(fd, isUserFd, buffer, 0, 8192);
if (bytesRead !== 0) {
buffers.push(buffer.slice(0, bytesRead));
}

This file was deleted.

Oops, something went wrong.

0 comments on commit 66f09be

Please sign in to comment.