os: restore some of the deprecated os.File methods

pull/7582/head
Delyan Angelov 2020-12-26 14:57:51 +02:00
parent 6969300f8a
commit e26e0c3f72
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 1 additions and 11 deletions

View File

@ -85,15 +85,11 @@ pub fn (mut f File) write_to(pos int, buf []byte) ?int {
return res
}
[deprecated]
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)
}
[deprecated]
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)
res := C.fwrite(data, 1, size, f.cfile)
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_bytes reads bytes from the beginning of the file
[deprecated]
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)
}
// 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 {
eprintln('warning `File.read_bytes_at()` has been deprecated, use `File.read_at` instead')
mut arr := []byte{len: size}
nreadbytes := f.read_bytes_into(pos, mut arr) or {
// return err
@ -120,12 +112,10 @@ pub fn (f &File) read_bytes_at(size int, pos int) []byte {
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.
// Returns number of bytes read or an error.
[deprecated]
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 {
panic(@FN + ': `buf.len` == 0')
}