Skip to content

Commit

Permalink
Rename {read,write}_offset to {read,write}_at, add a tracking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Aug 23, 2016
1 parent 1802011 commit 4e48924
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
30 changes: 15 additions & 15 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ impl File {
///
/// Note that similar to `File::read`, it is not an error to return a short
/// read.
#[unstable(feature = "file_offset", issue = "0")]
pub fn read_offset(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
self.inner.read_offset(buf, offset)
#[unstable(feature = "file_offset", issue = "35918")]
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
self.inner.read_at(buf, offset)
}

/// Writes a number of bytes starting from a given offset.
Expand All @@ -368,9 +368,9 @@ impl File {
///
/// Note that similar to `File::write`, it is not an error to return a
/// short write.
#[unstable(feature = "file_offset", issue = "0")]
pub fn write_offset(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
self.inner.write_offset(buf, offset)
#[unstable(feature = "file_offset", issue = "35918")]
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
self.inner.write_at(buf, offset)
}
}

Expand Down Expand Up @@ -1918,9 +1918,9 @@ mod tests {
}

#[test]
fn file_test_io_read_write_offset() {
fn file_test_io_read_write_at() {
let tmpdir = tmpdir();
let filename = tmpdir.join("file_rt_io_file_test_read_write_offset.txt");
let filename = tmpdir.join("file_rt_io_file_test_read_write_at.txt");
let mut buf = [0; 256];
let write1 = "asdf";
let write2 = "qwer-";
Expand All @@ -1929,35 +1929,35 @@ mod tests {
{
let oo = OpenOptions::new().create_new(true).write(true).read(true).clone();
let mut rw = check!(oo.open(&filename));
assert_eq!(check!(rw.write_offset(write1.as_bytes(), 5)), write1.len());
assert_eq!(check!(rw.write_at(write1.as_bytes(), 5)), write1.len());
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 0);
assert_eq!(check!(rw.read_offset(&mut buf, 5)), write1.len());
assert_eq!(check!(rw.read_at(&mut buf, 5)), write1.len());
assert_eq!(str::from_utf8(&buf[..write1.len()]), Ok(write1));
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 0);
assert_eq!(check!(rw.write(write2.as_bytes())), write2.len());
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 5);
assert_eq!(check!(rw.read(&mut buf)), write1.len());
assert_eq!(str::from_utf8(&buf[..write1.len()]), Ok(write1));
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 9);
assert_eq!(check!(rw.read_offset(&mut buf[..write2.len()], 0)), write2.len());
assert_eq!(check!(rw.read_at(&mut buf[..write2.len()], 0)), write2.len());
assert_eq!(str::from_utf8(&buf[..write2.len()]), Ok(write2));
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 9);
assert_eq!(check!(rw.write_offset(write3.as_bytes(), 9)), write3.len());
assert_eq!(check!(rw.write_at(write3.as_bytes(), 9)), write3.len());
assert_eq!(check!(rw.seek(SeekFrom::Current(0))), 9);
}
{
let mut read = check!(File::open(&filename));
assert_eq!(check!(read.read_offset(&mut buf, 0)), content.len());
assert_eq!(check!(read.read_at(&mut buf, 0)), content.len());
assert_eq!(str::from_utf8(&buf[..content.len()]), Ok(content));
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 0);
assert_eq!(check!(read.seek(SeekFrom::End(-5))), 9);
assert_eq!(check!(read.read_offset(&mut buf, 0)), content.len());
assert_eq!(check!(read.read_at(&mut buf, 0)), content.len());
assert_eq!(str::from_utf8(&buf[..content.len()]), Ok(content));
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 9);
assert_eq!(check!(read.read(&mut buf)), write3.len());
assert_eq!(str::from_utf8(&buf[..write3.len()]), Ok(write3));
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 14);
assert_eq!(check!(read.read_offset(&mut buf, 0)), content.len());
assert_eq!(check!(read.read_at(&mut buf, 0)), content.len());
assert_eq!(str::from_utf8(&buf[..content.len()]), Ok(content));
assert_eq!(check!(read.seek(SeekFrom::Current(0))), 14);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl FileDesc {
(&mut me).read_to_end(buf)
}

pub fn read_offset(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
let ret = cvt(unsafe {
libc::pread(self.fd,
buf.as_mut_ptr() as *mut c_void,
Expand All @@ -71,7 +71,7 @@ impl FileDesc {
Ok(ret as usize)
}

pub fn write_offset(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
let ret = cvt(unsafe {
libc::pwrite(self.fd,
buf.as_ptr() as *const c_void,
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,16 @@ impl File {
self.0.read_to_end(buf)
}

pub fn read_offset(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
self.0.read_offset(buf, offset)
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
self.0.read_at(buf, offset)
}

pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
}

pub fn write_offset(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
self.0.write_offset(buf, offset)
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
self.0.write_at(buf, offset)
}

pub fn flush(&self) -> io::Result<()> { Ok(()) }
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ impl File {
self.handle.read(buf)
}

pub fn read_offset(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
self.handle.read_offset(buf, offset)
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
self.handle.read_at(buf, offset)
}

pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
Expand All @@ -324,8 +324,8 @@ impl File {
self.handle.write(buf)
}

pub fn write_offset(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
self.handle.write_offset(buf, offset)
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
self.handle.write_at(buf, offset)
}

pub fn flush(&self) -> io::Result<()> { Ok(()) }
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/windows/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl RawHandle {
}
}

pub fn read_offset(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
let mut read = 0;
let len = cmp::min(buf.len(), <c::DWORD>::max_value() as usize) as c::DWORD;
unsafe {
Expand Down Expand Up @@ -189,7 +189,7 @@ impl RawHandle {
Ok(amt as usize)
}

pub fn write_offset(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
let mut written = 0;
let len = cmp::min(buf.len(), <c::DWORD>::max_value() as usize) as c::DWORD;
unsafe {
Expand Down

0 comments on commit 4e48924

Please sign in to comment.