From 496a802248af48c1c3ba88e68f9f5bf81a0846ed Mon Sep 17 00:00:00 2001 From: awiouy Date: Sat, 10 Feb 2018 16:26:08 +0100 Subject: [PATCH] core API: move subfile.rs to player.rs --- core/src/util/mod.rs | 2 -- core/src/util/subfile.rs | 38 ------------------------------------ playback/src/player.rs | 42 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 42 deletions(-) delete mode 100644 core/src/util/subfile.rs diff --git a/core/src/util/mod.rs b/core/src/util/mod.rs index f96a5431..d6cbdd68 100644 --- a/core/src/util/mod.rs +++ b/core/src/util/mod.rs @@ -8,11 +8,9 @@ use std::process::Command; mod int128; mod spotify_id; -mod subfile; pub use util::int128::u128; pub use util::spotify_id::{SpotifyId, FileId}; -pub use util::subfile::Subfile; pub fn rand_vec(rng: &mut G, size: usize) -> Vec { rng.gen_iter().take(size).collect() diff --git a/core/src/util/subfile.rs b/core/src/util/subfile.rs deleted file mode 100644 index 81d5d916..00000000 --- a/core/src/util/subfile.rs +++ /dev/null @@ -1,38 +0,0 @@ -use std::io::{Read, Seek, SeekFrom, Result}; - -pub struct Subfile { - stream: T, - offset: u64, -} - -impl Subfile { - pub fn new(mut stream: T, offset: u64) -> Subfile { - stream.seek(SeekFrom::Start(offset)).unwrap(); - Subfile { - stream: stream, - offset: offset, - } - } -} - -impl Read for Subfile { - fn read(&mut self, buf: &mut [u8]) -> Result { - self.stream.read(buf) - } -} - -impl Seek for Subfile { - fn seek(&mut self, mut pos: SeekFrom) -> Result { - pos = match pos { - SeekFrom::Start(offset) => SeekFrom::Start(offset + self.offset), - x => x, - }; - - let newpos = try!(self.stream.seek(pos)); - if newpos > self.offset { - Ok(newpos - self.offset) - } else { - Ok(0) - } - } -} diff --git a/playback/src/player.rs b/playback/src/player.rs index ffffa130..3958ab8a 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -1,15 +1,16 @@ use futures::sync::oneshot; use futures::{future, Future}; +use std; use std::borrow::Cow; +use std::io::{Read, Seek, SeekFrom, Result}; use std::mem; use std::sync::mpsc::{RecvError, TryRecvError, RecvTimeoutError}; use std::thread; use std::time::Duration; -use std; use core::config::{Bitrate, PlayerConfig}; use core::session::Session; -use core::util::{self, SpotifyId, Subfile}; +use core::util::{self, SpotifyId}; use audio_backend::Sink; use audio::{AudioFile, AudioDecrypt}; @@ -478,3 +479,40 @@ impl ::std::fmt::Debug for PlayerCommand { } } } + +struct Subfile { + stream: T, + offset: u64, +} + +impl Subfile { + pub fn new(mut stream: T, offset: u64) -> Subfile { + stream.seek(SeekFrom::Start(offset)).unwrap(); + Subfile { + stream: stream, + offset: offset, + } + } +} + +impl Read for Subfile { + fn read(&mut self, buf: &mut [u8]) -> Result { + self.stream.read(buf) + } +} + +impl Seek for Subfile { + fn seek(&mut self, mut pos: SeekFrom) -> Result { + pos = match pos { + SeekFrom::Start(offset) => SeekFrom::Start(offset + self.offset), + x => x, + }; + + let newpos = try!(self.stream.seek(pos)); + if newpos > self.offset { + Ok(newpos - self.offset) + } else { + Ok(0) + } + } +}