6 releases (breaking)
0.5.0 | Jul 23, 2024 |
---|---|
0.4.0 | Dec 5, 2023 |
0.3.0 | Sep 22, 2023 |
0.2.1 | Nov 23, 2022 |
0.1.0 | Jun 8, 2022 |
#51 in #slice
161 downloads per month
Used in tass
11KB
172 lines
Slices of files
FileSlice
is to File
what Bytes
is to
Vec<u8>
. Advantages over File
:
- You can slice it, reducing the scope to a range within the original file
- Cloning is cheap (atomic addition; no syscall)
- Seeking is very cheap (normal addition; no syscall)
- Clones can't affect each other at all (the fd's real cursor is never used).
Once created, a FileSlice
never changes length, even if the underlying file
does. For example, if another process appends some data to the file, you need
to call FileSlice::expand
on your slice in order to add the new data.
Optional features
Optional integrations for crates which naturally benefit from file slicing:
tar
: Adds aslice_tarball
helper method for splitting up atar::Archive
into a bunch ofFileSlice
s.parquet
: Adds aChunkReader
impl forFileSlice
. A parquet file contains many pages, and the decoder needs to interleave reads from these pages. TheChunkReader
impl forFile
accomplishes this by making many clones of the fd. UsingFileSlice
instead lets you open roughly 7x as many parquet files before you hit your fd limit.
Dependencies
~8–17MB
~256K SLoC