diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/display/client.nim | 8 | ||||
-rw-r--r-- | src/ips/serialize.nim | 44 | ||||
-rw-r--r-- | src/types/blob.nim | 3 |
3 files changed, 39 insertions, 16 deletions
diff --git a/src/display/client.nim b/src/display/client.nim index 98b8d7b7..d3878e49 100644 --- a/src/display/client.nim +++ b/src/display/client.nim @@ -15,8 +15,8 @@ import std/exitprocs import bindings/quickjs import buffer/container -import css/sheet import config/config +import css/sheet import data/charset import display/pager import display/term @@ -409,6 +409,12 @@ proc clientLoadJSModule(ctx: JSContext, module_name: cstring, JS_ThrowTypeError(ctx, "Failed to open file %s", module_name) return nil +proc readBlob(client: Client, path: string): Option[WebFile] {.jsfunc.} = + try: + return some(newWebFile(path)) + except IOError: + discard + #TODO this is dumb proc readFile(client: Client, path: string): string {.jsfunc.} = try: diff --git a/src/ips/serialize.nim b/src/ips/serialize.nim index beab3a5e..be5bbe28 100644 --- a/src/ips/serialize.nim +++ b/src/ips/serialize.nim @@ -283,25 +283,41 @@ func slen*(part: FormDataEntry): int = else: result += slen(part.value) +#TODO clean up this mess proc swrite*(stream: Stream, blob: Blob) = - stream.swrite(blob.ctype) - stream.swrite(blob.size) - #TODO ?? - stream.writeData(blob.buffer, int(blob.size)) + stream.swrite(blob.isfile) + if blob.isfile: + stream.swrite(WebFile(blob).path) + else: + stream.swrite(blob.ctype) + stream.swrite(blob.size) + stream.writeData(blob.buffer, int(blob.size)) proc sread*(stream: Stream, blob: var Blob) = - new(blob) - stream.sread(blob.ctype) - stream.sread(blob.size) - blob.buffer = alloc(blob.size) - blob.deallocFun = dealloc - #TODO ?? - assert stream.readData(blob.buffer, int(blob.size)) == int(blob.size) + var isfile: bool + stream.sread(isfile) + if isfile: + var file = new WebFile + file.isfile = true + stream.sread(file.path) + blob = file + else: + new(blob) + stream.sread(blob.ctype) + stream.sread(blob.size) + blob.buffer = alloc(blob.size) + blob.deallocFun = dealloc + if blob.size > 0: + assert stream.readData(blob.buffer, int(blob.size)) == int(blob.size) func slen*(blob: Blob): int = - result += slen(blob.ctype) - result += slen(blob.size) - result += int(blob.size) #TODO ?? + result += slen(blob.isfile) + if blob.isfile: + result = slen(WebFile(blob).path) + else: + result += slen(blob.ctype) + result += slen(blob.size) + result += int(blob.size) #TODO ?? proc swrite*[T](stream: Stream, o: Option[T]) = stream.swrite(o.issome) diff --git a/src/types/blob.nim b/src/types/blob.nim index 4a5627c3..d72d0505 100644 --- a/src/types/blob.nim +++ b/src/types/blob.nim @@ -34,7 +34,8 @@ proc finalize(blob: Blob) {.jsfin.} = proc newWebFile*(path: string, webkitRelativePath = ""): WebFile = var file: File - doAssert open(file, path, fmRead) #TODO bleh + if not open(file, path, fmRead): + raise newException(IOError, "Failed to open file") return WebFile( isfile: true, path: path, |