@@ -140,18 +140,18 @@ fn main() -> anyhow::Result<()> {
140
140
let files = opt. files . clone ( ) ;
141
141
142
142
// for each files present in the argument
143
- for file in files {
143
+ for path in files {
144
144
// 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 ) ;
147
147
}
148
148
149
149
let mime = match opt. format {
150
150
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" ) ?,
152
152
} ;
153
153
154
- let file_size = fs:: metadata ( & file ) ?. len ( ) ;
154
+ let file_size = if path == Path :: new ( "-" ) { 0 } else { fs:: metadata ( & path ) ?. len ( ) } ;
155
155
let size = opt. batch_size . as_u64 ( ) as usize ;
156
156
let nb_chunks = file_size / size as u64 ;
157
157
let pb = ProgressBar :: new ( nb_chunks) ;
@@ -160,21 +160,21 @@ fn main() -> anyhow::Result<()> {
160
160
match mime {
161
161
Mime :: Json => {
162
162
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 ) ?;
164
164
send_data ( & opt, & agent, opt. upload_operation , & pb, & mime, data. as_bytes ( ) ) ?;
165
165
}
166
166
pb. inc ( 1 ) ;
167
167
}
168
168
Mime :: NdJson => {
169
- for chunk in nd_json:: NdJsonChunker :: new ( file , size) {
169
+ for chunk in nd_json:: NdJsonChunker :: new ( path , size) {
170
170
if opt. skip_batches . zip ( pb. length ( ) ) . map_or ( true , |( s, l) | s > l) {
171
171
send_data ( & opt, & agent, opt. upload_operation , & pb, & mime, & chunk) ?;
172
172
}
173
173
pb. inc ( 1 ) ;
174
174
}
175
175
}
176
176
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 ) {
178
178
if opt. skip_batches . zip ( pb. length ( ) ) . map_or ( true , |( s, l) | s > l) {
179
179
send_data ( & opt, & agent, opt. upload_operation , & pb, & mime, & chunk) ?;
180
180
}
0 commit comments