Skip to content

Commit

Permalink
There are services that neither streamable nor seekable
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Feb 3, 2023
1 parent 3301a46 commit 5590150
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
38 changes: 17 additions & 21 deletions src/layers/type_eraser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,15 @@ impl<A: Accessor> TypeEraseAccessor<A> {
let content_length = rp.metadata().content_length();

match (seekable, streamable) {
(true, true) => {
(true, true) => Ok((rp, Box::new(r))),
(true, false) => {
let r = output::into_reader::as_streamable(r, 256 * 1024);
Ok((rp, Box::new(r)))
}
(false, true) => {
match (range.offset(), range.size()) {
(Some(offset), _) => {
let r= output::into_reader::by_range(self.inner.clone(), path, r, offset, content_length);

Ok((rp, Box::new(r)))
}
_ => {
let (offset, size) = match (range.offset(), range.size()) {
(Some(offset), _) => (offset, content_length),
(None, None) => (0, content_length),
(None, Some(size)) => {
// TODO: we can read content range to calculate
// the total content length.
Expand All @@ -80,22 +79,19 @@ impl<A: Accessor> TypeEraseAccessor<A> {
} else {
(total_size - size, size)
};
let r= output::into_reader::by_range(self.inner.clone(), path,r, offset, size);

Ok((rp, Box::new(r)))
},
(None, None) => {
let r = output::into_reader::by_range(self.inner.clone(), path, r,0, content_length);

Ok((rp, Box::new(r)))
(offset, size)
}
}
}
(true, false) => {
let r = output::into_reader::as_streamable(r, 256 * 1024);
Ok((rp, Box::new(r)))
};
let r = output::into_reader::by_range(self.inner.clone(), path, r, offset, size);

if streamable {
Ok((rp, Box::new(r)))
} else {
let r = output::into_reader::as_streamable(r, 256 * 1024);
Ok((rp, Box::new(r)))
}
}
(false, false) => unreachable!("reader is neither seekable nor streamable, please check if service {} implemented correctly", self.meta.scheme()),
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/services/ftp/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ impl Accessor for Backend {
.set_root(&self.root)
.set_capabilities(
AccessorCapability::Read | AccessorCapability::Write | AccessorCapability::List,
)
.set_hints(AccessorHint::ReadIsStreamable);
);

am
}
Expand Down

1 comment on commit 5590150

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for opendal ready!

✅ Preview
https://opendal-qy0jqdgq6-databend.vercel.app
https://opendal-git-type-exercise.vercel.app

Built with commit 5590150.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.