os: restore some of the deprecated os.File methods
parent
6969300f8a
commit
e26e0c3f72
|
@ -85,15 +85,11 @@ pub fn (mut f File) write_to(pos int, buf []byte) ?int {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
[deprecated]
|
|
||||||
pub fn (mut f File) write_bytes(data voidptr, size int) int {
|
pub fn (mut f File) write_bytes(data voidptr, size int) int {
|
||||||
eprintln('warning `File.write_bytes()` has been deprecated, use `File.write` instead')
|
|
||||||
return C.fwrite(data, 1, size, f.cfile)
|
return C.fwrite(data, 1, size, f.cfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
[deprecated]
|
|
||||||
pub fn (mut f File) write_bytes_at(data voidptr, size int, pos int) int {
|
pub fn (mut f File) write_bytes_at(data voidptr, size int, pos int) int {
|
||||||
eprintln('warning `File.write_bytes_at()` has been deprecated, use `File.write_at` instead')
|
|
||||||
C.fseek(f.cfile, pos, C.SEEK_SET)
|
C.fseek(f.cfile, pos, C.SEEK_SET)
|
||||||
res := C.fwrite(data, 1, size, f.cfile)
|
res := C.fwrite(data, 1, size, f.cfile)
|
||||||
C.fseek(f.cfile, 0, C.SEEK_END)
|
C.fseek(f.cfile, 0, C.SEEK_END)
|
||||||
|
@ -102,16 +98,12 @@ pub fn (mut f File) write_bytes_at(data voidptr, size int, pos int) int {
|
||||||
|
|
||||||
// **************************** Read ops ***************************
|
// **************************** Read ops ***************************
|
||||||
// read_bytes reads bytes from the beginning of the file
|
// read_bytes reads bytes from the beginning of the file
|
||||||
[deprecated]
|
|
||||||
pub fn (f &File) read_bytes(size int) []byte {
|
pub fn (f &File) read_bytes(size int) []byte {
|
||||||
eprintln('warning `File.read_bytes()` has been deprecated, use `File.read` instead')
|
|
||||||
return f.read_bytes_at(size, 0)
|
return f.read_bytes_at(size, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read_bytes_at reads bytes at the given position in the file
|
// read_bytes_at reads bytes at the given position in the file
|
||||||
[deprecated]
|
|
||||||
pub fn (f &File) read_bytes_at(size int, pos int) []byte {
|
pub fn (f &File) read_bytes_at(size int, pos int) []byte {
|
||||||
eprintln('warning `File.read_bytes_at()` has been deprecated, use `File.read_at` instead')
|
|
||||||
mut arr := []byte{len: size}
|
mut arr := []byte{len: size}
|
||||||
nreadbytes := f.read_bytes_into(pos, mut arr) or {
|
nreadbytes := f.read_bytes_into(pos, mut arr) or {
|
||||||
// return err
|
// return err
|
||||||
|
@ -120,12 +112,10 @@ pub fn (f &File) read_bytes_at(size int, pos int) []byte {
|
||||||
return arr[0..nreadbytes]
|
return arr[0..nreadbytes]
|
||||||
}
|
}
|
||||||
|
|
||||||
// read_bytes_from fills `buf` with bytes at the given position in the file.
|
// read_bytes_into fills `buf` with bytes at the given position in the file.
|
||||||
// `buf` must have length greater than zero.
|
// `buf` must have length greater than zero.
|
||||||
// Returns number of bytes read or an error.
|
// Returns number of bytes read or an error.
|
||||||
[deprecated]
|
|
||||||
pub fn (f &File) read_bytes_into(pos int, mut buf []byte) ?int {
|
pub fn (f &File) read_bytes_into(pos int, mut buf []byte) ?int {
|
||||||
eprintln('warning `File.read_bytes_into()` has been deprecated, use `File.read_from_into` instead')
|
|
||||||
if buf.len == 0 {
|
if buf.len == 0 {
|
||||||
panic(@FN + ': `buf.len` == 0')
|
panic(@FN + ': `buf.len` == 0')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue