pub struct File {
pub id: i64,
pub name: String,
pub permissions: u8,
pub size: u32,
pub path: String,
pub symlink: String,
pub tags: Vec<String>,
/* private fields */
}Expand description
Single file object.
Represents a file and it’s properties that can be downloaded and written to a file system.
Fields§
§id: i64Id of the file.
name: StringFile name.
permissions: u8Permissions for the given file.
size: u32Size of the file entry in bytes.
path: StringAbsolute path to the file, where root is one of the directory entries.
symlink: StringSymbolic link of the file.
A vector of applicable tags.
Implementations§
source§impl File
impl File
sourcepub fn parse(
file: &FileEntry,
tag_entries: &HashMap<u8, String>,
directories: &HashMap<i64, (String, i64)>,
chunk_entries: &HashMap<i64, (i64, u32, u32, u32)>
) -> Result<Self>
pub fn parse( file: &FileEntry, tag_entries: &HashMap<u8, String>, directories: &HashMap<i64, (String, i64)>, chunk_entries: &HashMap<i64, (i64, u32, u32, u32)> ) -> Result<Self>
Parses FileEntry into a File object.
First parameter is a FileEntry that is parsed into a File, the other three are
HashMaps used for fast lookups for the required data.
Here is how they are structured:
-
Parameter
tag_entriesis aHashMapwhere the key is a tag id and the value is a tag name. -
Parameter
directoriesis aHashMapwhere the key is a directory id and the value is a tuple of: -
Parameter
chunk_entriesis aHashMapwhere the key is a chunk id and the value is a tuple of:- bundle id,
- offset in bundle (to this specific chunk),
- uncompressed size
- and compressed size.
Errors
If a directory with provided id or
parent id does not exist within the
directories HashMap, or if a chunk with
chunk id does not exist within the chunk_entries
HashMap, the error FileParseError is
returned.
source§impl File
impl File
sourcepub async fn download<W: Write + Send, U: IntoUrl + Send>(
&self,
writer: W,
bundle_url: U
) -> Result<()>
pub async fn download<W: Write + Send, U: IntoUrl + Send>( &self, writer: W, bundle_url: U ) -> Result<()>
Function to download the associated file contents.
This is done by looping through all of the chunks of this file, and for each loop:
- get the bundle id it belongs to, and convert it to hexadecimal value with a fixed size of 16 (if the length is less than 16, zeros are padded to the left).
- download the chunk from the url using the range header
- decompress the chunk
- write chunk.
Errors
If downloading fails, the error ReqwestError is
returned.
If converting uncompressed_size to usize fails,
the error ConversionFailure is returned.
If zstd decompression fails, the error
ZstdDecompressError is returned.
If writing to io stream fails, the error IoError is
returned.
Examples
See downloading a file.
Trait Implementations§
source§impl PartialEq<File> for File
impl PartialEq<File> for File
impl Eq for File
impl StructuralEq for File
impl StructuralPartialEq for File
Auto Trait Implementations§
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnwindSafe for File
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.