diff options
author | bptato <nincsnevem662@gmail.com> | 2023-09-17 13:36:38 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-09-17 13:36:38 +0200 |
commit | 84a7c65b62e5ff322a23b91c2e80d517d41ed504 (patch) | |
tree | ae635f3d9a7f9fa0d6b07bdf168a0a7a9b707827 /src/types | |
parent | ba2d0b1d8dae67b6f8d3e815a61d26c7c0b1ce2f (diff) | |
download | chawan-84a7c65b62e5ff322a23b91c2e80d517d41ed504.tar.gz |
response: add blob() function
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/blob.nim | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/types/blob.nim b/src/types/blob.nim index 54071c33..b6ef4adf 100644 --- a/src/types/blob.nim +++ b/src/types/blob.nim @@ -7,7 +7,7 @@ import utils/mimeguess import utils/twtstr type - DeallocFun = proc(buffer: pointer) {.noconv.} + DeallocFun = proc() {.closure.} Blob* = ref object of RootObj isfile*: bool @@ -35,12 +35,12 @@ proc newBlob*(buffer: pointer, size: int, ctype: string, proc finalize(blob: Blob) {.jsfin.} = if blob.deallocFun != nil and blob.buffer != nil: - blob.deallocFun(blob.buffer) + blob.deallocFun() blob.buffer = nil proc finalize(file: WebFile) {.jsfin.} = if file.deallocFun != nil and file.buffer != nil: - file.deallocFun(file.buffer) + file.deallocFun() file.buffer = nil proc newWebFile*(path: string, webkitRelativePath = ""): WebFile = @@ -68,12 +68,13 @@ proc newWebFile(ctx: JSContext, fileBits: seq[string], fileName: string, let file = WebFile( isfile: false, path: fileName, - deallocFun: dealloc ) var len = 0 for blobPart in fileBits: len += blobPart.len - file.buffer = alloc(len) + let buffer = alloc(len) + file.buffer = buffer + file.deallocFun = proc() = dealloc(buffer) var buf = cast[ptr UncheckedArray[uint8]](file.buffer) var i = 0 for blobPart in fileBits: |