/* Reads the specified number of bytes into a the supplied buffer, returing * the number actually read. */ MVMint64 MVM_io_syncstream_read_bytes(MVMThreadContext *tc, MVMOSHandle *h, char **buf, MVMint64 bytes) { MVMIOSyncStreamData *data = (MVMIOSyncStreamData *)h->body.data; ensure_decode_stream(tc, data); /* See if we've already enough; if not, try and grab more. */ if (!MVM_string_decodestream_have_bytes(tc, data->ds, bytes)) read_to_buffer(tc, data, bytes > CHUNK_SIZE ? bytes : CHUNK_SIZE); /* Read as many as we can, up to the limit. */ return MVM_string_decodestream_bytes_to_buf(tc, data->ds, buf, bytes); }
/* Reads the specified number of bytes into a the supplied buffer, returing * the number actually read. */ static MVMint64 read_bytes(MVMThreadContext *tc, MVMOSHandle *h, char **buf, MVMint64 bytes) { MVMIOFileData *data = (MVMIOFileData *)h->body.data; ensure_decode_stream(tc, data); /* Keep requesting bytes until we have enough in the buffer or we hit * end of file. */ while (!MVM_string_decodestream_have_bytes(tc, data->ds, bytes)) { if (read_to_buffer(tc, data, bytes) <= 0) break; } /* Read as many as we can, up to the limit. */ return MVM_string_decodestream_bytes_to_buf(tc, data->ds, buf, bytes); }