forked from pcwalton/rust-media
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstreaming.rs
More file actions
31 lines (27 loc) · 1.04 KB
/
streaming.rs
File metadata and controls
31 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2015 The Servo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::old_io::fs::File;
use std::old_io::{Reader, Seek};
pub trait StreamReader : Reader + Seek {
/// Returns the number of bytes available in this stream.
fn available_size(&self) -> u64;
/// Returns the total number of octets in this stream, including those that are not yet
/// available.
fn total_size(&self) -> u64;
}
/// TODO(pcwalton): Should probably buffer reads, maybe by implementing on BufferedReader<File> or
/// something.
impl StreamReader for File {
fn available_size(&self) -> u64 {
self.total_size()
}
fn total_size(&self) -> u64 {
self.stat().unwrap().size
}
}