tail: When tailing a file in bytes mode, seek directly to the specified byte

When tailing a file, as opposed to stdin, and we are tailing bytes rather than
lines, we can seek the requested number of bytes from the end of the file. This
side steps the whole `backwards_thru_file` file loop and blocks of reads.

Fixes #833.
This commit is contained in:
Nick Fitzgerald 2016-03-27 14:29:47 -07:00
parent f851611001
commit 2b2c2b64c2

View file

@ -336,11 +336,8 @@ fn bounded_tail(mut file: File, settings: &Settings) {
}
});
},
FilterMode::Bytes(mut count) => {
backwards_thru_file(&mut file, size, &mut buf, &mut |_| {
count -= 1;
count == 0
});
FilterMode::Bytes(count) => {
file.seek(SeekFrom::End(-(count as i64))).unwrap();
},
}