-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.m
87 lines (72 loc) · 2.08 KB
/
stream.m
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
stream ; Stream Class
; Copyright (C) 2008 Etienne Cherdlu <80n80n@gmail.com>
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU Affero General Public License as
; published by the Free Software Foundation, either version 3 of the
; License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
openFile(stream,fileName) ; Public ; Create a stream object for a file and open the stream
;
o fileName:READ
;
s stream("current")=""
s stream("fileName")=fileName
s stream("recordCount")=0
s stream("type")="file"
;
q
openPipe(stream,fileName) ; Public ; Create a stream object for a pipe and open the stream
;
o fileName:FIFO
;
s stream("current")=""
s stream("fileName")=fileName
s stream("recordCount")=0
s stream("type")="pipe"
;
q
openPayload(stream) ; Public ; Create a stream object for an http payload
;
s stream("current")=""
s stream("i")=""
s stream("recordCount")=0
s stream("type")="payload"
;
q
read(stream) ; Public ; Read a record from a stream
;
n line
;
; Get the next line
i stream("type")="payload" d
. s stream("i")=$o(^serverLink("payload",$j,stream("i"))) i stream("i")="" s line="" q
. s line=^serverLink("payload",$j,stream("i"))
e u stream("fileName") r line
;
s stream("current")=line
s stream("recordCount")=stream("recordCount")+1
;
q line
close(stream) ; Public ; Close the stream and destroy the stream object
;
i stream("type")="payload" ; no-op
e c stream("fileName")
k stream
q
eof(stream) ; Public ; End of File?
;
n eof
;
s eof=0
i stream("type")="payload",stream("i")="" s eof=1
i stream("type")="pipe" w 1/0 ; TODO
i stream("type")="file" w 1/0 ; TODO
q eof