@@ -36,7 +36,7 @@ function Base.eof(stream::TranscodingStream)
36
36
if state. mode == :init
37
37
return eof (stream. stream)
38
38
elseif state. mode == :read
39
- return isemptybuf (state) && fillbuffer (stream) == 0 && eof (stream. stream)
39
+ return buffersize (state) == 0 && fillbuffer (stream) == 0 && eof (stream. stream)
40
40
elseif state. mode == :write
41
41
return eof (stream. stream)
42
42
elseif state. mode == :closed
@@ -82,9 +82,8 @@ function Base.read(stream::TranscodingStream, ::Type{UInt8})
82
82
throw (EOFError ())
83
83
end
84
84
state = stream. state
85
- # @assert state.position < state.fposition
86
- b = state. data[state. position]
87
- state. position += 1
85
+ b = state. data[state. bufferpos]
86
+ state. bufferpos += 1
88
87
return b
89
88
end
90
89
@@ -94,10 +93,10 @@ function Base.unsafe_read(stream::TranscodingStream, output::Ptr{UInt8}, nbytes:
94
93
p = output
95
94
p_end = output + nbytes
96
95
while p < p_end && ! eof (stream)
97
- m = min (state. fposition - state . position , nbytes)
96
+ m = min (buffersize ( state) , nbytes)
98
97
unsafe_copy! (p, bufferptr (state), m)
99
98
p += m
100
- state. position += m
99
+ state. bufferpos += m
101
100
end
102
101
if p < p_end && eof (stream)
103
102
throw (EOFError ())
107
106
108
107
function Base. nb_available (stream:: TranscodingStream )
109
108
prepare (stream, :read )
110
- return stream. state. fposition - stream . state . position
109
+ return buffersize ( stream. state)
111
110
end
112
111
113
112
@@ -117,11 +116,11 @@ end
117
116
function Base. write (stream:: TranscodingStream , b:: UInt8 )
118
117
prepare (stream, :write )
119
118
state = stream. state
120
- if isfullbuf (state) && flushbuffer (stream) == 0
119
+ if marginsize (state) == 0 && flushbuffer (stream) == 0
121
120
return 0
122
121
end
123
- state. data[state. position ] = b
124
- state. position += 1
122
+ state. data[state. marginpos ] = b
123
+ state. marginpos += 1
125
124
return 1
126
125
end
127
126
@@ -131,13 +130,13 @@ function Base.unsafe_write(stream::TranscodingStream, input::Ptr{UInt8}, nbytes:
131
130
p = input
132
131
p_end = p + nbytes
133
132
while p < p_end
134
- if isfullbuf (state) && flushbuffer (stream) == 0
133
+ if marginsize (state) == 0 && flushbuffer (stream) == 0
135
134
break
136
135
end
137
- m = min (endof (state. data) - (state . fposition - 1 ), p_end - p)
136
+ m = min (marginsize (state), p_end - p)
138
137
unsafe_copy! (marginptr (state), p, m)
139
138
p += m
140
- state. fposition += m
139
+ state. marginpos += m
141
140
end
142
141
return Int (p - input)
143
142
end
@@ -153,9 +152,9 @@ function fillbuffer(stream::TranscodingStream)::Int
153
152
end
154
153
nfilled = 0
155
154
makemargin! (state, 1 )
156
- while ! isfullbuf (state) && state. proc != PROC_FINISH
155
+ while marginsize (state) > 0 && state. proc != PROC_FINISH
157
156
n, code = process (Read, stream. codec, stream. stream, marginptr (state), marginsize (state))
158
- state. fposition += n
157
+ state. marginpos += n
159
158
state. proc = code
160
159
nfilled += n
161
160
end
@@ -168,9 +167,9 @@ function flushbuffer(stream::TranscodingStream)::Int
168
167
return 0
169
168
end
170
169
nflushed = 0
171
- while ! isemptybuf (state)
170
+ while buffersize (state) > 0
172
171
n, code = process (Write, stream. codec, stream. stream, bufferptr (state), buffersize (state))
173
- state. position += n
172
+ state. bufferpos += n
174
173
state. proc = code
175
174
nflushed += n
176
175
end
0 commit comments