Skip to content

Commit

Permalink
fix: HDFS doesn't support seek from end (#114)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Jul 11, 2023
1 parent 94b1d4d commit 5a58375
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io::{Error, Read, Result, Seek, SeekFrom, Write};
use std::io::{Error, ErrorKind, Read, Result, Seek, SeekFrom, Write};
use std::ptr;

use hdfs_sys::*;
Expand Down Expand Up @@ -186,12 +186,10 @@ impl Seek for &File {
self.inner_seek(offset as i64)?;
Ok(offset)
}
SeekFrom::End(n) => {
let meta = Client::new(self.fs).metadata(&self.path)?;
let offset = meta.len() as i64 + n;
self.inner_seek(offset)?;
Ok(offset as u64)
}
SeekFrom::End(_) => Err(Error::new(
ErrorKind::Unsupported,
"hdfs doesn't support seek from end",
)),
}
}
}
Expand Down

0 comments on commit 5a58375

Please sign in to comment.