mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #2227 from jfinkels/tail-iocopy-bounded-tail
tail: use std::io::copy() to write bytes to stdout
This commit is contained in:
commit
cacd078a49
1 changed files with 3 additions and 15 deletions
|
@ -19,7 +19,6 @@ mod chunks;
|
||||||
mod platform;
|
mod platform;
|
||||||
mod ringbuffer;
|
mod ringbuffer;
|
||||||
use chunks::ReverseChunks;
|
use chunks::ReverseChunks;
|
||||||
use chunks::BLOCK_SIZE;
|
|
||||||
use ringbuffer::RingBuffer;
|
use ringbuffer::RingBuffer;
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
|
@ -442,8 +441,6 @@ fn backwards_thru_file(file: &mut File, num_delimiters: usize, delimiter: u8) {
|
||||||
/// `BLOCK_SIZE` until we find the location of the first line/byte. This ends up
|
/// `BLOCK_SIZE` until we find the location of the first line/byte. This ends up
|
||||||
/// being a nice performance win for very large files.
|
/// being a nice performance win for very large files.
|
||||||
fn bounded_tail(file: &mut File, settings: &Settings) {
|
fn bounded_tail(file: &mut File, settings: &Settings) {
|
||||||
let mut buf = vec![0; BLOCK_SIZE as usize];
|
|
||||||
|
|
||||||
// Find the position in the file to start printing from.
|
// Find the position in the file to start printing from.
|
||||||
match settings.mode {
|
match settings.mode {
|
||||||
FilterMode::Lines(count, delimiter) => {
|
FilterMode::Lines(count, delimiter) => {
|
||||||
|
@ -455,18 +452,9 @@ fn bounded_tail(file: &mut File, settings: &Settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the target section of the file.
|
// Print the target section of the file.
|
||||||
loop {
|
let stdout = stdout();
|
||||||
let bytes_read = file.read(&mut buf).unwrap();
|
let mut stdout = stdout.lock();
|
||||||
|
std::io::copy(file, &mut stdout).unwrap();
|
||||||
let mut stdout = stdout();
|
|
||||||
for b in &buf[0..bytes_read] {
|
|
||||||
print_byte(&mut stdout, *b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes_read == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collect the last elements of an iterator into a `VecDeque`.
|
/// Collect the last elements of an iterator into a `VecDeque`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue