Skip to content

Commit cb3ef97

Browse files
committed
fix: change FileDetail creating logic and base64 import
1 parent 949a5aa commit cb3ef97

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/output.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22
use std::io::{self, Write};
33

4-
use base64::{engine::general_purpose, Engine as _};
4+
use base64::{prelude::BASE64_STANDARD, Engine as _};
55
use jiff::Timestamp;
66
use lscolors::{Indicator, LsColors, Style};
77

@@ -269,7 +269,7 @@ impl<'a, W: Write> Printer<'a, W> {
269269
writeln!(
270270
self.stdout,
271271
"path_base64: \"{}\"",
272-
general_purpose::STANDARD.encode(bytes)
272+
BASE64_STANDARD.encode(bytes)
273273
)?;
274274
}
275275
}
@@ -316,7 +316,7 @@ impl<'a, W: Write> Printer<'a, W> {
316316
write!(
317317
self.stdout,
318318
"\"path_b64\":\"{}\"",
319-
general_purpose::STANDARD.encode(path_bytes)
319+
BASE64_STANDARD.encode(path_bytes)
320320
)?;
321321
}
322322
}
@@ -346,16 +346,7 @@ impl<'a, W: Write> Printer<'a, W> {
346346
let encoded_path = encode_path(path);
347347
let metadata = entry.metadata();
348348

349-
let mut detail = FileDetail {
350-
path: encoded_path,
351-
file_type: "unknown".to_string(),
352-
size: None,
353-
mode: None,
354-
modified: None,
355-
accessed: None,
356-
created: None,
357-
};
358-
if let Some(meta) = metadata {
349+
let detail = if let Some(meta) = metadata {
359350
let size = meta.len();
360351
let mode = {
361352
#[cfg(unix)]
@@ -393,14 +384,26 @@ impl<'a, W: Write> Printer<'a, W> {
393384
.and_then(|d| Timestamp::from_second(d.as_secs() as i64).ok())
394385
});
395386

396-
detail.file_type = ft;
397-
detail.size = Some(size);
398-
detail.mode = mode;
399-
detail.modified = modified;
400-
detail.accessed = accessed;
401-
detail.created = created;
402-
}
403-
387+
FileDetail {
388+
path: encoded_path,
389+
file_type: ft,
390+
size: Some(size),
391+
mode,
392+
modified,
393+
accessed,
394+
created,
395+
}
396+
} else {
397+
FileDetail {
398+
path: encoded_path,
399+
file_type: "unknown".to_string(),
400+
size: None,
401+
mode: None,
402+
modified: None,
403+
accessed: None,
404+
created: None,
405+
}
406+
};
404407
match format {
405408
OutputFormat::Json => self.print_entry_json_obj(&detail, true),
406409
OutputFormat::Ndjson => self.print_entry_json_obj(&detail, false),

0 commit comments

Comments
 (0)