bug: wrong chunk offset
This commit is contained in:
parent
d197c06688
commit
7edadd7ca1
2 changed files with 15 additions and 7 deletions
|
|
@ -35,7 +35,7 @@ fn main() {
|
|||
info!("file: {file:?}");
|
||||
|
||||
for chunk in file.chunked(args.chunk_size * 1024 * 1024).seek(0) {
|
||||
info!("chunk len: {}", chunk.bytes.len());
|
||||
info!("chunk: {chunk:?}");
|
||||
|
||||
file.upload_chunk(&agent, &alias, &chunk)
|
||||
.unwrap_or_else(|e| {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use std::{
|
||||
fmt::Debug,
|
||||
fs::File,
|
||||
io::{Read, Seek, SeekFrom},
|
||||
path::Path,
|
||||
|
|
@ -34,10 +35,12 @@ impl Iterator for FileChunks<'_> {
|
|||
type Item = Chunk;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let offset = self.offset;
|
||||
|
||||
let mut f = File::open(self.file_path)
|
||||
.inspect_err(|e| error!("Error opening file: {e}"))
|
||||
.ok()?;
|
||||
f.seek(SeekFrom::Start(self.offset)).ok()?;
|
||||
f.seek(SeekFrom::Start(offset)).ok()?;
|
||||
|
||||
let mut bytes = vec![0; self.chunk_size];
|
||||
let read_len = (f.read(&mut bytes))
|
||||
|
|
@ -51,11 +54,7 @@ impl Iterator for FileChunks<'_> {
|
|||
.ok()?;
|
||||
self.offset += read_len;
|
||||
|
||||
Some(Self::Item {
|
||||
offset: self.offset,
|
||||
bytes,
|
||||
})
|
||||
.filter(|c| !c.bytes.is_empty())
|
||||
Some(Self::Item { offset, bytes }).filter(|c| !c.bytes.is_empty())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +63,15 @@ pub struct Chunk {
|
|||
pub bytes: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Debug for Chunk {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Chunk")
|
||||
.field("offset", &self.offset)
|
||||
.field("len", &self.bytes.len())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Chunk {
|
||||
pub fn after(&self) -> u64 {
|
||||
let len: u64 = self.bytes.len().try_into().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue