forked from rsenn/qjs-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickjs-blob.h
54 lines (44 loc) · 1.11 KB
/
quickjs-blob.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef QUICKJS_BLOB_H
#define QUICKJS_BLOB_H
#include "utils.h"
#include "vector.h"
#include "buffer-utils.h"
/**
* \defgroup quickjs-blob quickjs-blob: Blob
* @{
*/
typedef union blob {
struct {
uint8_t* data;
size_t size, capacity;
BOOL error;
DynBufReallocFunc* realloc_func;
void* opaque;
char* type;
};
Vector vec;
} Blob;
extern VISIBLE JSClassID js_blob_class_id;
extern VISIBLE JSValue blob_proto, blob_ctor;
Blob* blob_new(JSContext*, const void* x, size_t len, const char* type);
ssize_t blob_write(JSContext*, Blob* blob, const void* x, size_t len);
void blob_free(JSRuntime*, Blob* blob);
InputBuffer blob_input(JSContext*, Blob* blob);
VISIBLE JSValue js_blob_wrap(JSContext*, Blob* blob);
VISIBLE JSValue js_blob_new(JSContext*, const void* x, size_t len, const char* type);
static inline void*
blob_data(Blob* blob) {
return blob->data;
}
static inline size_t
blob_size(Blob* blob) {
return blob->size;
}
static inline Blob*
js_blob_data(JSContext* ctx, JSValueConst value) {
return JS_GetOpaque(value, js_blob_class_id);
}
/**
* @}
*/
#endif /* defined(QUICKJS_BLOB_H) */