Struct retdec::file::File [] [src]

pub struct File { /* fields omitted */ }

In-memory representation of a file.

Only the name and content of a file are accessible. Path to the file is not stored.

Examples

use std::path::Path;
use retdec::file::File;

let file = File::from_path("tests/file.exe")?;

assert_eq!(file.name(), "file.exe");

let saved_file_path = file.save_into("another_dir")?;
assert_eq!(saved_file_path, Path::new("another_dir/file.exe"));

Methods

impl File
[src]

Creates a file from the given path.

The name is detected automatically from the path.

Examples

use retdec::file::File;

let file = File::from_path("tests/file.exe")?;

assert_eq!(file.name(), "file.exe");

Creates a file from the given path but gives it a custom name.

Examples

use retdec::file::File;

let file = File::from_path_with_custom_name("tests/file.exe", "other.exe")?;

assert_eq!(file.name(), "other.exe");

Creates a file with the given content and name.

Examples

use retdec::file::File;

let file = File::from_content_with_name(b"content", "file.txt");

assert_eq!(file.content(), b"content");
assert_eq!(file.name(), "file.txt");

Returns the raw content of the file.

Examples

use retdec::file::File;

let file = File::from_content_with_name(b"content", "file.txt");

assert_eq!(file.content(), b"content");

Returns the content of the file as text.

The content is expected to be encoded as UTF-8, which is the encoding that retdec.com's API uses.

Examples

use retdec::file::File;

let file = File::from_content_with_name(b"content", "file.txt");

assert_eq!(file.content_as_text()?, "content");

Returns the number of bytes in the content.

Examples

use retdec::file::File;

let file = File::from_content_with_name(b"content", "file.txt");

assert_eq!(file.content_len(), 7);

Returns the name of the file.

Examples

use retdec::file::File;

let file = File::from_content_with_name(b"content", "file.txt");

assert_eq!(file.name(), "file.txt");

Returns a modified version of the file's name that can be passed to the retdec.com's API.

Examples

use retdec::file::File;

let file = File::from_content_with_name(b"content", "jalapeño.txt");

assert_eq!(file.safe_name(), "jalapeno.txt");

Stores a copy of the file into the given directory.

Returns a path to the saved file.

Examples

use std::path::Path;
use retdec::file::File;

let file = File::from_path("tests/file.exe")?;

let saved_file_path = file.save_into("another_dir")?;
assert_eq!(saved_file_path, Path::new("another_dir/file.exe"));

Stores a copy of the file into the given directory under a custom name.

Returns a path to the saved file.

Examples

use std::path::Path;
use retdec::file::File;

let file = File::from_path("tests/file.exe")?;

let saved_file_path = file.save_into_under_name("another_dir", "test.exe")?;
assert_eq!(saved_file_path, Path::new("another_dir/test.exe"));

Stores a copy of the file into the given path.

The path is expected to be a file path. If you want to store the file into a directory, use either save_into() or save_into_under_name().

Examples

use retdec::file::File;

let file = File::from_path("tests/file.exe")?;

file.save_as("another_dir/test.exe")?;

Trait Implementations

impl Clone for File
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for File
[src]

Formats the value using the given formatter.