fix(write): use shared Error type for write()

This commit is contained in:
Kat Marchán 2019-06-05 11:33:45 +02:00
parent e5aeb669b4
commit 8bf623b8ef
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
1 changed files with 8 additions and 5 deletions

View File

@ -1,11 +1,14 @@
use atomicwrites::{AtomicFile, AllowOverwrite};
use crate::content::path;
use ssri::{Algorithm, Integrity};
use std::fs::DirBuilder;
use std::io::{self, prelude::*};
use std::io::prelude::*;
use std::path::Path;
pub fn write(cache: &Path, data: &[u8]) -> io::Result<Integrity> {
use atomicwrites::{AtomicFile, AllowOverwrite};
use ssri::{Algorithm, Integrity};
use crate::content::path;
use crate::errors::Error;
pub fn write(cache: &Path, data: &[u8]) -> Result<Integrity, Error> {
let sri = Integrity::from(&data, Algorithm::Sha256);
let cpath = path::content_path(&cache, &sri);
DirBuilder::new().recursive(true).create(cpath.parent().unwrap())?;