summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-05-27 06:17:25 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-05-27 06:17:25 -0700
commit29c6d17108aca455ac5c7e2e26b996f3b0cb4469 (patch)
tree3535aa7d2d697e5adac7fe656153f4276e3fdbbe /stdlib
parent3fc97c29d1407756bb3e7e36c40cfed966ef82f7 (diff)
downloadtxr-29c6d17108aca455ac5c7e2e26b996f3b0cb4469.tar.gz
txr-29c6d17108aca455ac5c7e2e26b996f3b0cb4469.tar.bz2
txr-29c6d17108aca455ac5c7e2e26b996f3b0cb4469.zip
I/O convenience functions get mode-opt argument.
This is motivated by the desired to be able to specify gzip compression: e.g. (file-put-string "file.gz" "abc" "z") However, it has other uses. For instance with "x", we can exclusively create a file with content in one call. * stdlib/getput.tl (file-get, file-put, file-append, file-get-string, file-put-string, file-append-string, file-put-lines, file-append-lines, file-get-buf, file-put-buf, file-place-buf, file-append-buf, file-get-json, file-put-json, file-append-json, file-get-jsons, file-put-jsons, file-append-jsons): New option argument which combines with the open-file mode. * txr.1: Documented.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/getput.tl72
1 files changed, 36 insertions, 36 deletions
diff --git a/stdlib/getput.tl b/stdlib/getput.tl
index 7c5b4542..d9717593 100644
--- a/stdlib/getput.tl
+++ b/stdlib/getput.tl
@@ -62,83 +62,83 @@
(put-jsonl obj s flat-p))
t)
-(defun file-get (name)
- (with-stream (s (open-file name))
+(defun file-get (name : mopt)
+ (with-stream (s (open-file name `r@mopt`))
(read s)))
-(defun file-put (name obj)
- (with-stream (s (open-file name "w"))
+(defun file-put (name obj : mopt)
+ (with-stream (s (open-file name `w@mopt`))
(prinl obj s)))
-(defun file-append (name obj)
- (with-stream (s (open-file name "a"))
+(defun file-append (name obj : mopt)
+ (with-stream (s (open-file name `a@mopt`))
(prinl obj s)))
-(defun file-get-string (name)
- (with-stream (s (open-file name))
+(defun file-get-string (name : mopt)
+ (with-stream (s (open-file name `r@mopt`))
(get-string s)))
-(defun file-put-string (name string)
- (with-stream (s (open-file name "w"))
+(defun file-put-string (name string : mopt)
+ (with-stream (s (open-file name `w@mopt`))
(put-string string s)))
-(defun file-append-string (name string)
- (with-stream (s (open-file name "a"))
+(defun file-append-string (name string : mopt)
+ (with-stream (s (open-file name `a@mopt`))
(put-string string s)))
(defun file-get-lines (name)
(get-lines (open-file name)))
-(defun file-put-lines (name lines)
- (with-stream (s (open-file name "w"))
+(defun file-put-lines (name lines : mopt)
+ (with-stream (s (open-file name `w@mopt`))
(put-lines lines s)))
-(defun file-append-lines (name lines)
- (with-stream (s (open-file name "a"))
+(defun file-append-lines (name lines : mopt)
+ (with-stream (s (open-file name `a@mopt`))
(put-lines lines s)))
-(defun file-get-buf (name : bytes (seek 0))
- (with-stream (s (open-file name (if bytes "rbu" "rb")))
+(defun file-get-buf (name : bytes (seek 0) mopt)
+ (with-stream (s (open-file name `rb@(if bytes "u")@mopt`))
(sys:get-buf-common s bytes seek)))
-(defun file-put-buf (name buf : (seek 0))
- (with-stream (s (open-file name "wb"))
+(defun file-put-buf (name buf : (seek 0) mopt)
+ (with-stream (s (open-file name `wb@mopt`))
(unless (zerop seek)
(seek-stream s seek :from-current))
(put-buf buf 0 s)))
-(defun file-place-buf (name buf : (seek 0))
- (with-stream (s (open-file name "mb"))
+(defun file-place-buf (name buf : (seek 0) mopt)
+ (with-stream (s (open-file name `mb@mopt`))
(unless (zerop seek)
(seek-stream s seek :from-current))
(put-buf buf 0 s)))
-(defun file-append-buf (name buf)
- (with-stream (s (open-file name "ab"))
+(defun file-append-buf (name buf : mopt)
+ (with-stream (s (open-file name `ab@mopt`))
(put-buf buf 0 s)))
-(defun file-get-json (name)
- (with-stream (s (open-file name))
+(defun file-get-json (name : mopt)
+ (with-stream (s (open-file name `r@mopt`))
(get-json s)))
-(defun file-put-json (name obj : flat-p)
- (with-stream (s (open-file name "w"))
+(defun file-put-json (name obj : flat-p mopt)
+ (with-stream (s (open-file name `w@mopt`))
(put-jsonl obj s flat-p)))
-(defun file-append-json (name obj : flat-p)
- (with-stream (s (open-file name "a"))
+(defun file-append-json (name obj : flat-p mopt)
+ (with-stream (s (open-file name `a@mopt`))
(put-jsonl obj s flat-p)))
-(defun file-get-jsons (name)
- (with-stream (s (open-file name))
+(defun file-get-jsons (name : mopt)
+ (with-stream (s (open-file name `r@mopt`))
(get-jsons s)))
-(defun file-put-jsons (name seq : flat-p)
- (with-stream (s (open-file name "w"))
+(defun file-put-jsons (name seq : flat-p mopt)
+ (with-stream (s (open-file name `w@mopt`))
(put-jsons seq s flat-p)))
-(defun file-append-jsons (name seq : flat-p)
- (with-stream (s (open-file name "a"))
+(defun file-append-jsons (name seq : flat-p mopt)
+ (with-stream (s (open-file name `a@mopt`))
(put-jsons s seq flat-p)))
(defun command-get (cmd)