mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-25 17:24:48 +10:00
Converted to using BufWriters instead of streaming everything at once
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@@ -3,11 +3,11 @@ use crate::db::DatabaseImpls;
|
|||||||
use crate::downloads::manifest::DropDownloadContext;
|
use crate::downloads::manifest::DropDownloadContext;
|
||||||
use crate::DB;
|
use crate::DB;
|
||||||
use atomic_counter::{AtomicCounter, RelaxedCounter};
|
use atomic_counter::{AtomicCounter, RelaxedCounter};
|
||||||
use log::info;
|
use log::{error, info};
|
||||||
use md5::{Context, Digest};
|
use md5::{Context, Digest};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{File, OpenOptions},
|
fs::{File, OpenOptions},
|
||||||
io::{self, Error, ErrorKind, Seek, SeekFrom, Write},
|
io::{self, BufWriter, Error, ErrorKind, Seek, SeekFrom, Write},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||||
@@ -100,15 +100,19 @@ pub fn download_game_chunk(ctx: DropDownloadContext, callback: Arc<AtomicBool>,
|
|||||||
// Writing everything to disk directly is probably slightly faster because it balances out the writes,
|
// Writing everything to disk directly is probably slightly faster because it balances out the writes,
|
||||||
// but this is better than the performance loss from constantly reading the callbacks
|
// but this is better than the performance loss from constantly reading the callbacks
|
||||||
|
|
||||||
//let mut writer = BufWriter::with_capacity(1024 * 1024, file);
|
let mut writer = BufWriter::with_capacity(1024 * 1024, file);
|
||||||
|
|
||||||
//copy_to_drop_file_writer(&mut response, &mut file);
|
//copy_to_drop_file_writer(&mut response, &mut file);
|
||||||
match io::copy(&mut response, &mut file) {
|
match io::copy(&mut response, &mut writer) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
info!("Copy errored with error {}", e)
|
info!("Copy errored with error {}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let file = match writer.into_inner() {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(_) => {error!("Failed to acquire writer from BufWriter"); return; }
|
||||||
|
};
|
||||||
|
|
||||||
let res = hex::encode(file.finish().unwrap().0);
|
let res = hex::encode(file.finish().unwrap().0);
|
||||||
if res != ctx.checksum {
|
if res != ctx.checksum {
|
||||||
|
|||||||
Reference in New Issue
Block a user