summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-11-17 07:30:15 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-11-17 07:30:15 -0800
commitc860aa452e10b450b2edeb64b6812d95e826c611 (patch)
tree7fd4e8436fd72cfe7041d3b0d85a013e4c7082b9
parent9108e9f8f4434fb29200b08a4b576df47c407c01 (diff)
downloadtxr-c860aa452e10b450b2edeb64b6812d95e826c611.tar.gz
txr-c860aa452e10b450b2edeb64b6812d95e826c611.tar.bz2
txr-c860aa452e10b450b2edeb64b6812d95e826c611.zip
buffers: use unbuffered I/O in convenience functions.
* stdlib/getput.tl (file-get-buf, command-get-buf): If the number of bytes to read is specified, we use an unbuffered stream. A buffered stream can read more bytes in order to fill a buffer, which is undesirable when dealing with a device or pipe.
-rw-r--r--stdlib/getput.tl4
-rw-r--r--txr.16
2 files changed, 8 insertions, 2 deletions
diff --git a/stdlib/getput.tl b/stdlib/getput.tl
index 4102853e..3b583d73 100644
--- a/stdlib/getput.tl
+++ b/stdlib/getput.tl
@@ -97,7 +97,7 @@
(put-lines lines s)))
(defun file-get-buf (name : bytes (seek 0))
- (with-stream (s (open-file name "rb"))
+ (with-stream (s (open-file name (if bytes "rbu" "rb")))
(sys:get-buf-common s bytes seek)))
(defun file-put-buf (name buf : (seek 0))
@@ -164,7 +164,7 @@
(put-lines lines s)))
(defun command-get-buf (cmd : bytes (skip 0))
- (with-stream (s (open-command cmd "rb"))
+ (with-stream (s (open-command cmd (if bytes "rbu" "rb")))
(sys:get-buf-common s bytes skip)))
(defun command-put-buf (cmd buf)
diff --git a/txr.1 b/txr.1
index 28274987..e95238a8 100644
--- a/txr.1
+++ b/txr.1
@@ -27515,6 +27515,12 @@ If possible, the semantics of this parameter is achieved by performing a
operation, falling back on reading and discarding bytes if the
stream doesn't support seeking.
+If
+.meta max-bytes
+is specified, then the stream is opened in unbuffered mode, so that bytes
+beyond the specified range shall not be requested from the underlying file,
+device or process.
+
.coNP Functions @, file-put-buf @ file-append-buf and @ command-put-buf
.synb
.mets (file-put-buf < name < buf << skip-bytes )