diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-12 17:03:35 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-12 17:03:35 +0100 |
commit | 8e6783a45fba48dd8f63fe7486e4691f05220b52 (patch) | |
tree | 5aae9f9f95432609a497eea858c4a3401dac172b /src/io | |
parent | 69b1a7e7f6e0a675cd70805768162de5621e8279 (diff) | |
download | chawan-8e6783a45fba48dd8f63fe7486e4691f05220b52.tar.gz |
Remove CLONE BufferSource; cache document sources in tmpdir
At last all BufferSources are unified. To achieve the same effect as the previous CLONE source type, we now use the "fromcache" flag in Request. This *forces* the document to be streamed from the disk; if the file no longer exists for some reason, an error is returned (i.e. the document is not re-downloaded). For a document to be cached, it has to be the main document of the buffer (i.e. no additional resources requested with fetch()), and also not an x-htmloutput HTML file (for those, the original source is saved). The result is that toggleSource now always returns the actual source for e.g. markdown files, not the HTML-transformed version. Also, it is now possible to view the source of a document that is still being downloaded. buffer.sstream has almost been eliminated; it still exists, but only as a pseudo-buffer to interface with EncoderStream and DecoderStream. It no longer holds the entire source of a buffer at any point, and is cleared as soon as the buffer is completely loaded.
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/posixstream.nim | 6 | ||||
-rw-r--r-- | src/io/serialize.nim | 37 |
2 files changed, 6 insertions, 37 deletions
diff --git a/src/io/posixstream.nim b/src/io/posixstream.nim index 0cc6ff73..1b615dce 100644 --- a/src/io/posixstream.nim +++ b/src/io/posixstream.nim @@ -104,3 +104,9 @@ proc newPosixStream*(fd: FileHandle): PosixStream = writeDataImpl: psWriteData, atEndImpl: psAtEnd ) + +proc newPosixStream*(path: string, flags, mode: cint): PosixStream = + let fd = open(cstring(path), flags, mode) + if fd == -1: + return nil + return newPosixStream(fd) diff --git a/src/io/serialize.nim b/src/io/serialize.nim index f27fb40d..2e2480e6 100644 --- a/src/io/serialize.nim +++ b/src/io/serialize.nim @@ -5,9 +5,7 @@ import std/sets import std/streams import std/tables -import loader/request import types/blob -import types/buffersource import types/formdata import types/url import types/opt @@ -72,10 +70,6 @@ proc swrite*[T, E](stream: Stream, o: Result[T, E]) proc sread*[T, E](stream: Stream, o: var Result[T, E]) func slen*[T, E](o: Result[T, E]): int -proc swrite*(stream: Stream, source: BufferSource) -proc sread*(stream: Stream, source: var BufferSource) -func slen*(source: BufferSource): int - proc swrite*(stream: Stream, n: SomeNumber) = stream.write(n) @@ -383,34 +377,3 @@ func slen*[T, E](o: Result[T, E]): int = else: when not (E is void): result += slen(o.error) - -proc swrite*(stream: Stream, source: BufferSource) = - stream.swrite(source.t) - case source.t - of CLONE: stream.swrite(source.clonepid) - of LOAD_REQUEST: stream.swrite(source.request) - stream.swrite(source.location) - stream.swrite(source.contentType) - stream.swrite(source.charset) - -proc sread*(stream: Stream, source: var BufferSource) = - var t: BufferSourceType - stream.sread(t) - case t - of CLONE: - source = BufferSource(t: CLONE) - stream.sread(source.clonepid) - of LOAD_REQUEST: - source = BufferSource(t: LOAD_REQUEST) - stream.sread(source.request) - stream.sread(source.location) - stream.sread(source.contentType) - stream.sread(source.charset) - -func slen*(source: BufferSource): int = - result += slen(source.t) - case source.t - of CLONE: result += slen(source.clonepid) - of LOAD_REQUEST: result += slen(source.request) - result += slen(source.location) - result += slen(source.contentType) |