2
0
Fork 0

[chunks] extract to plain memory

personal/stbuehler/wip
Stefan Bühler 2013-05-17 15:38:20 +02:00
parent 092a1b0141
commit 20a63070e2
2 changed files with 20 additions and 6 deletions

View File

@ -202,6 +202,7 @@ INLINE liChunkIter li_chunkqueue_iter(liChunkQueue *cq);
INLINE liChunk* li_chunkqueue_first_chunk(liChunkQueue *cq);
LI_API gboolean li_chunkqueue_extract_to(liChunkQueue *cq, goffset len, GString *dest, GError **err);
LI_API gboolean li_chunkqueue_extract_to_memory(liChunkQueue *cq, goffset len, void *dest, GError **err);
LI_API gboolean li_chunkqueue_extract_to_bytearr(liChunkQueue *cq, goffset len, GByteArray *dest, GError **err);
/* helper functions to append to the last BUFFER_CHUNK of a chunkqueue */

View File

@ -842,18 +842,15 @@ error:
return FALSE;
}
gboolean li_chunkqueue_extract_to_bytearr(liChunkQueue *cq, goffset len, GByteArray *dest, GError **err) {
gboolean li_chunkqueue_extract_to_memory(liChunkQueue *cq, goffset len, void *dest, GError **err) {
liChunkIter ci;
goffset coff, clen;
unsigned char *cdest = (unsigned char*) dest;
g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
g_byte_array_set_size(dest, 0);
if (len > cq->length) return FALSE;
g_byte_array_set_size(dest, len);
g_byte_array_set_size(dest, 0);
ci = li_chunkqueue_iter(cq);
while (len > 0) {
@ -863,7 +860,8 @@ gboolean li_chunkqueue_extract_to_bytearr(liChunkQueue *cq, goffset len, GByteAr
gchar *buf;
off_t we_have;
if (LI_HANDLER_GO_ON != li_chunkiter_read(ci, coff, len, &buf, &we_have, err)) goto error;
g_byte_array_append(dest, (guint8*) buf, we_have);
memcpy(cdest, buf, we_have);
cdest += we_have;
coff += we_have;
len -= we_have;
if (len <= 0) return TRUE;
@ -878,6 +876,21 @@ error:
return FALSE;
}
gboolean li_chunkqueue_extract_to_bytearr(liChunkQueue *cq, goffset len, GByteArray *dest, GError **err) {
g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
if (len > cq->length) return FALSE;
g_byte_array_set_size(dest, len);
if (!li_chunkqueue_extract_to_memory(cq, len, dest->data, err)) {
g_byte_array_set_size(dest, 0);
return FALSE;
}
return TRUE;
}
/* helper functions to append to the last BUFFER_CHUNK of a chunkqueue */
/* returns the liBuffer from the last chunk in cq, if the chunk has type BUFFER_CHUNK,