From 70cf52e136624bbff415d2641d56331191649f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Wed, 22 May 2019 19:42:34 -0700 Subject: [PATCH] feat(read): added content read and read_to_string --- src/content/read.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/content/read.rs b/src/content/read.rs index 4d5d525..4c30286 100644 --- a/src/content/read.rs +++ b/src/content/read.rs @@ -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 { +pub fn open(cache: &Path, sri: &Integrity) -> io::Result { File::open(content_path(&cache, &sri)) } -pub fn copy(cache: &Path, sri: &Integrity, to: &Path) -> std::io::Result { - std::fs::copy(content_path(&cache, &sri), to) +pub fn read(cache: &Path, sri: &Integrity) -> io::Result> { + fs::read(content_path(&cache, &sri)) +} + +pub fn read_to_string(cache: &Path, sri: &Integrity) -> io::Result { + fs::read_to_string(content_path(&cache, &sri)) +} + +pub fn copy(cache: &Path, sri: &Integrity, to: &Path) -> io::Result { + fs::copy(content_path(&cache, &sri), to) }