Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  downloader.rs

  Sprache: Rust
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */


use std::fs::{exists, File};
use std::io::copy;
use std::os::unix::fs::symlink;
use std::path::Path;

use anyhow::Result;
use log::info;
use ureq;

/// A simple trait to facilitate unit testing of functions that download files.
pub(cratetrait FileDownloader {
    fn fetch(&self, url: &str, dest: &Path, cache_dir: &Path) -> Result<()>;
}

pub(cratestruct UreqDownloader;

impl FileDownloader for UreqDownloader {
    fn fetch(&self, url: &str, dest: &Path, cache_dir: &Path) -> Result<()> {
        let mut cached_path = cache_dir.to_path_buf();
        cached_path.push(url_to_filename(url));

        if exists(&cached_path)? {
            info!(
                "{} already exists, not downloading {}",
                cached_path.display(),
                url
            );
        } else {
            info!("Downloading {} to {}", url, cached_path.display());
            let mut response = ureq::get(url).call()?.into_body().into_reader();
            let mut dest_file = File::create(&cached_path)?;
            copy(&mut response, &mut dest_file)?;
        }

        // The file we want is now at `cached_path`; now we can symlink it to
        // the desired location.
        symlink(cached_path, dest)?;

        return Ok(());
    }
}

fn url_to_filename(url: &str) -> String {
    return url.replace(":""_").replace("/""_");
}

Messung V0.5 in Prozent
C=92 H=100 G=95

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002