5 releases (3 breaking)

0.4.0 Dec 5, 2023
0.3.0 Sep 22, 2023
0.2.1 Nov 23, 2022
0.2.0 Jun 10, 2022
0.1.0 Jun 8, 2022

#727 in Rust patterns

Download history 271/week @ 2023-12-17 303/week @ 2023-12-24 281/week @ 2023-12-31 492/week @ 2024-01-07 571/week @ 2024-01-14 568/week @ 2024-01-21 524/week @ 2024-01-28 175/week @ 2024-02-04 427/week @ 2024-02-11 464/week @ 2024-02-18 707/week @ 2024-02-25 675/week @ 2024-03-03 521/week @ 2024-03-10 733/week @ 2024-03-17 430/week @ 2024-03-24 560/week @ 2024-03-31

2,245 downloads per month
Used in tass

Unlicense

10KB
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 a slice_tarball helper method for splitting up a tar::Archive into a bunch of FileSlices.
  • parquet: Adds a ChunkReader impl for FileSlice. A parquet file contains many pages, and the decoder needs to interleave reads from these pages. The ChunkReader impl for File accomplishes this by making many clones of the fd. Using FileSlice instead lets you open roughly 7x as many parquet files before you hit your fd limit.

Dependencies

~7–18MB
~238K SLoC