From 07aba05860fa550fb72a3e3e71c95f5c87b4a337 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 17 Nov 2021 07:30:15 -0800 Subject: 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. --- stdlib/getput.tl | 4 ++-- txr.1 | 6 ++++++ 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 ) -- cgit v1.2.3