Skip to content

Commit dd7da47

Browse files
committed
Do our best with the progress bar when using stdin
1 parent 5030a99 commit dd7da47

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,18 @@ fn main() -> anyhow::Result<()> {
140140
let files = opt.files.clone();
141141

142142
// for each files present in the argument
143-
for file in files {
143+
for path in files {
144144
// check if the file exists
145-
if file != Path::new("-") && !file.exists() {
146-
anyhow::bail!("The file {:?} does not exist", file);
145+
if path != Path::new("-") && !path.exists() {
146+
anyhow::bail!("The file {:?} does not exist", path);
147147
}
148148

149149
let mime = match opt.format {
150150
Some(mime) => mime,
151-
None => Mime::from_path(&file).context("Could not find the mime type")?,
151+
None => Mime::from_path(&path).context("Could not find the mime type")?,
152152
};
153153

154-
let file_size = fs::metadata(&file)?.len();
154+
let file_size = if path == Path::new("-") { 0 } else { fs::metadata(&path)?.len() };
155155
let size = opt.batch_size.as_u64() as usize;
156156
let nb_chunks = file_size / size as u64;
157157
let pb = ProgressBar::new(nb_chunks);
@@ -160,21 +160,21 @@ fn main() -> anyhow::Result<()> {
160160
match mime {
161161
Mime::Json => {
162162
if opt.skip_batches.zip(pb.length()).map_or(true, |(s, l)| s > l) {
163-
let data = fs::read_to_string(file)?;
163+
let data = fs::read_to_string(path)?;
164164
send_data(&opt, &agent, opt.upload_operation, &pb, &mime, data.as_bytes())?;
165165
}
166166
pb.inc(1);
167167
}
168168
Mime::NdJson => {
169-
for chunk in nd_json::NdJsonChunker::new(file, size) {
169+
for chunk in nd_json::NdJsonChunker::new(path, size) {
170170
if opt.skip_batches.zip(pb.length()).map_or(true, |(s, l)| s > l) {
171171
send_data(&opt, &agent, opt.upload_operation, &pb, &mime, &chunk)?;
172172
}
173173
pb.inc(1);
174174
}
175175
}
176176
Mime::Csv => {
177-
for chunk in csv::CsvChunker::new(file, size, opt.csv_delimiter) {
177+
for chunk in csv::CsvChunker::new(path, size, opt.csv_delimiter) {
178178
if opt.skip_batches.zip(pb.length()).map_or(true, |(s, l)| s > l) {
179179
send_data(&opt, &agent, opt.upload_operation, &pb, &mime, &chunk)?;
180180
}

0 commit comments

Comments
 (0)