Offset operations can currently be performed with seek, but some concise APIs are missing
These APIs are more semantic and easier to understand
Golang also provides a similar API
import (
"fmt"
"os"
)
func main() {
f, _ := os.OpenFile("1.go", os.O_RDWR, os.ModePerm)
f.WriteAt([]byte("widuu"), 10) // write at offset = 10
b := make([]byte, 20)
d, _ := f.ReadAt(b, 10) // read from offset = 10
fmt.Println(string(b[:d])) //widuudhellowordhello
}
const file = Deno.open("./file.txt")
const bytes = new Uint8Array(10)
file.readAt(bytes, 20); // Read 10 bytes of data with an offset of 20
mock api
async function readAt(bytes: Uint8Array, offset: number) {
await this.seek(offset, 0)
await this.read(b)
await this.seek(0, 0) // reset offset
return b
}
same as above
Should have the API to quickly read/write some data from file
Or maybe extend the Deno.read(b: Uint8Array) API to Deno.read(b: Uint8Array, offset?: number) will be better?
Am in need of this for implementing pread/pwrite in https://deno.land/x/wasi.
Adding an optional offset is the way to go IMHO.
This issue has been open for a while - I'll work on it.
I'm jumping on this one.
Is anyone actively working on this?
Hey, I'm not. I assumed the person who posted after me was taking it. It doesn't look like anyone is working on it
@caspervonb @fvkramer i have something started but i'm also having a kid like with in 2 weeks.... so if you get this done just toss it out there.
Most helpful comment
@caspervonb @fvkramer i have something started but i'm also having a kid like with in 2 weeks.... so if you get this done just toss it out there.