blob: 7f9c2af26f873ac10b3cbc3078dfd34b22b26116 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
(defun sys:get-buf-common (s bytes seek)
(let ((b (make-buf 0 0 (min bytes 4096)))
(o 0))
(when (plusp seek)
(unless (ignerr (seek-stream s seek :from-current))
(let ((b (make-buf (min seek 4096)))
(c 0))
(while (< c seek)
(let ((p (fill-buf b 0 s)))
(if (zerop p)
(return))
(inc c p))))))
(while (or (null bytes) (< (len b) bytes))
(let ((p (fill-buf-adjust b o s)))
(when (= p o)
(return))
(set o p)
(when (eql p (buf-alloc-size b))
(buf-set-length b (min (+ p p) bytes)))))
b))
(defun file-get (name)
(with-stream (s (open-file name))
(read s)))
(defun file-put (name obj)
(with-stream (s (open-file name "w"))
(prinl obj s)))
(defun file-append (name obj)
(with-stream (s (open-file name "a"))
(prinl obj s)))
(defun file-get-string (name)
(with-stream (s (open-file name))
(get-string s)))
(defun file-put-string (name string)
(with-stream (s (open-file name "w"))
(put-string string s)))
(defun file-append-string (name string)
(with-stream (s (open-file name "a"))
(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"))
(put-lines lines s)))
(defun file-append-lines (name lines)
(with-stream (s (open-file name "a"))
(put-lines lines s)))
(defun file-get-buf (name : bytes (seek 0))
(with-stream (s (open-file name "rb"))
(sys:get-buf-common s bytes seek)))
(defun file-put-buf (name buf : (seek 0))
(with-stream (s (open-file name "wb"))
(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"))
(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"))
(put-buf buf 0 s)))
(defun command-get (cmd)
(with-stream (s (open-command cmd))
(read s)))
(defun command-put (cmd obj)
(with-stream (s (open-command cmd "w"))
(prinl obj s)))
(defun command-get-string (cmd)
(with-stream (s (open-command cmd))
(get-string s)))
(defun command-put-string (cmd string)
(with-stream (s (open-command cmd "w"))
(put-string string s)))
(defun command-get-lines (cmd)
(get-lines (open-command cmd)))
(defun command-put-lines (cmd lines)
(with-stream (s (open-command cmd "w"))
(put-lines lines s)))
(defun command-get-buf (cmd : bytes (skip 0))
(with-stream (s (open-command cmd "rb"))
(sys:get-buf-common s bytes skip)))
(defun command-put-buf (cmd buf)
(with-stream (s (open-command cmd "wb"))
(put-buf buf 0 s)))
|