summary refs log tree commit diff
path: root/src/libstd/rt/io/file.rs
blob: a99f5da032c39757bc0ec04b297cae74b46b8a80 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// 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 prelude::*;
use super::support::PathLike;
use super::{Reader, Writer, Seek};
use super::SeekStyle;

/// # XXX
/// * Ugh, this is ridiculous. What is the best way to represent these options?
enum FileMode {
    /// Opens an existing file. IoError if file does not exist.
    Open,
    /// Creates a file. IoError if file exists.
    Create,
    /// Opens an existing file or creates a new one.
    OpenOrCreate,
    /// Opens an existing file or creates a new one, positioned at EOF.
    Append,
    /// Opens an existing file, truncating it to 0 bytes.
    Truncate,
    /// Opens an existing file or creates a new one, truncating it to 0 bytes.
    CreateOrTruncate,
}

enum FileAccess {
    Read,
    Write,
    ReadWrite
}

pub struct FileStream;

impl FileStream {
    pub fn open<P: PathLike>(_path: &P,
                             _mode: FileMode,
                             _access: FileAccess
                            ) -> Option<FileStream> {
        fail!()
    }
}

impl Reader for FileStream {
    fn read(&mut self, _buf: &mut [u8]) -> Option<uint> {
        fail!()
    }

    fn eof(&mut self) -> bool {
        fail!()
    }
}

impl Writer for FileStream {
    fn write(&mut self, _v: &[u8]) { fail!() }

    fn flush(&mut self) { fail!() }
}

impl Seek for FileStream {
    fn tell(&self) -> u64 { fail!() }

    fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
}

#[test]
#[ignore]
fn super_simple_smoke_test_lets_go_read_some_files_and_have_a_good_time() {
    let message = "it's alright. have a good time";
    let filename = &Path("test.txt");
    let mut outstream = FileStream::open(filename, Create, Read).unwrap();
    outstream.write(message.as_bytes());
}