# close the stream
fun close is abstract
+
+ # Pre-work hook.
+ #
+ # Used to inform `self` that operations will start.
+ # Specific streams can use this to prepare some resources.
+ #
+ # Is automatically invoked at the beginning of `with` structures.
+ #
+ # Do nothing by default.
+ fun start do end
+
+ # Post-work hook.
+ #
+ # Used to inform `self` that the operations are over.
+ # Specific streams can use this to free some resources.
+ #
+ # Is automatically invoked at the end of `woth` structures.
+ #
+ # call `close` by default.
+ fun finish do close
end
# A `Stream` that can be read from
# if this is the best size or not
var chunksz = 129
if chunksz > remsp then
- rets += new FlatString.with_infos(sits, remsp, pos, pos + remsp - 1)
+ rets += new FlatString.with_infos(sits, remsp, pos)
break
end
var st = sits.find_beginning_of_char_at(pos + chunksz - 1)
var bytelen = st - pos
- rets += new FlatString.with_infos(sits, bytelen, pos, st - 1)
+ rets += new FlatString.with_infos(sits, bytelen, pos)
pos = st
remsp -= bytelen
end
end
end
+redef class Bytes
+ super Writable
+ redef fun write_to(s) do s.write_bytes(self)
+
+ redef fun write_to_string do return to_s
+end
+
redef class Text
super Writable
redef fun write_to(stream) do stream.write(self)