Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static read(
fd: Descriptor,
data: Array = [],
chunk_size: usize = 4096
): Array | null {
let data_partial_len = chunk_size;
let data_partial = changetype(new ArrayBuffer(data_partial_len));
let iov = changetype(new ArrayBuffer(2 * sizeof()));
store(iov, data_partial);
store(iov + sizeof(), data_partial_len);
let read_ptr = changetype(new ArrayBuffer(sizeof()));
fd_read(fd, iov, 1, read_ptr);
let read = load(read_ptr);
if (read > 0) {
for (let i: usize = 0; i < read; i++) {
data.push(load(data_partial + i));
}
}
if (read <= 0) {
return null;
}
return data;
}
static readAll(
fd: Descriptor,
data: Array = [],
chunk_size: usize = 4096
): Array | null {
let data_partial_len = chunk_size;
let data_partial = changetype(new ArrayBuffer(data_partial_len));
let iov = changetype(new ArrayBuffer(2 * sizeof()));
store(iov, data_partial);
store(iov + sizeof(), data_partial_len);
let read_ptr = changetype(new ArrayBuffer(sizeof()));
let read: usize = 0;
for (; ;) {
if (fd_read(fd, iov, 1, read_ptr) != errno.SUCCESS) {
break;
}
read = load(read_ptr);
if (read <= 0) {
break;
}
for (let i: usize = 0; i < read; i++) {
data.push(load(data_partial + i));
}
}
if (read < 0) {
return null;
}
return data;
}