Skip to content

Commit

Permalink
Revert "fs: ensure readFile[Sync] reads from the beginning"
Browse files Browse the repository at this point in the history
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 66f09be
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
10 changes: 5 additions & 5 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down
23 changes: 0 additions & 23 deletions test/parallel/test-fs-readfile-fd-offset.js

This file was deleted.

0 comments on commit 66f09be

Please sign in to comment.