diff --git a/core/src/services/sftp/backend.rs b/core/src/services/sftp/backend.rs index d6ec3c08041..8e3c103f786 100644 --- a/core/src/services/sftp/backend.rs +++ b/core/src/services/sftp/backend.rs @@ -396,8 +396,6 @@ impl Access for SftpBackend { .await .map_err(parse_sftp_error)?; - let meta = f.metadata().await.map_err(parse_sftp_error)?; - if args.range().offset() != 0 { f.seek(SeekFrom::Start(args.range().offset())) .await @@ -406,7 +404,7 @@ impl Access for SftpBackend { Ok(( RpRead::default(), - SftpReader::new(client, f, args.range().size().and(meta.len())), + SftpReader::new(client, f, args.range().size()), )) } diff --git a/core/src/services/sftp/reader.rs b/core/src/services/sftp/reader.rs index 6b4ceeff1cc..936e315acd1 100644 --- a/core/src/services/sftp/reader.rs +++ b/core/src/services/sftp/reader.rs @@ -50,7 +50,7 @@ impl SftpReader { impl oio::Read for SftpReader { async fn read(&mut self) -> Result { - if Some(self.read) >= self.size { + if self.read >= self.size.unwrap_or(usize::MAX) { return Ok(Buffer::new()); } @@ -71,6 +71,8 @@ impl oio::Read for SftpReader { }; self.read += bytes.len(); - Ok(Buffer::from(bytes.freeze())) + self.buf = bytes; + let bs = self.buf.split(); + Ok(Buffer::from(bs.freeze())) } }