feat(read): added content read and read_to_string

This commit is contained in:
Kat Marchán 2019-05-22 19:42:34 -07:00
parent e452fdcd16
commit 70cf52e136
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
1 changed files with 13 additions and 4 deletions

View File

@ -1,12 +1,21 @@
use crate::content::path::content_path;
use ssri::Integrity;
use std::path::Path;
use std::fs::File;
use std::fs::{self, File};
use std::io;
pub fn open(cache: &Path, sri: &Integrity) -> std::io::Result<File> {
pub fn open(cache: &Path, sri: &Integrity) -> io::Result<File> {
File::open(content_path(&cache, &sri))
}
pub fn copy(cache: &Path, sri: &Integrity, to: &Path) -> std::io::Result<u64> {
std::fs::copy(content_path(&cache, &sri), to)
pub fn read(cache: &Path, sri: &Integrity) -> io::Result<Vec<u8>> {
fs::read(content_path(&cache, &sri))
}
pub fn read_to_string(cache: &Path, sri: &Integrity) -> io::Result<String> {
fs::read_to_string(content_path(&cache, &sri))
}
pub fn copy(cache: &Path, sri: &Integrity, to: &Path) -> io::Result<u64> {
fs::copy(content_path(&cache, &sri), to)
}