core :: FileWriter
Stream
that can write to a Filecore :: FileWriter :: _is_writable
core :: FileWriter :: defaultinit
core :: FileWriter :: from_fd
Creates a new File stream from a file descriptorcore :: FileWriter :: is_writable=
core :: FileWriter :: write_native
Writelen
bytes from native
.
core $ FileWriter :: SELF
Type of this instance, automatically specialized in every classcore $ FileWriter :: write_bytes_from_cstring
Writelen
bytes from ns
binary :: BinaryStream :: _big_endian
Use the big-endian convention? otherwise use little-endian.core :: FileWriter :: _is_writable
core :: Stream :: _last_error
Error produced by the file streamcore :: Stream :: _lookahead_capacity
Capacity of the lookaheadcore :: Stream :: _lookahead_length
Current occupation of the lookaheadcore :: Stream :: _write_buffer
Buffer for writing data to a streambinary :: BinaryStream :: big_endian
Use the big-endian convention? otherwise use little-endian.binary :: BinaryStream :: big_endian=
Use the big-endian convention? otherwise use little-endian.core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: FileStream :: defaultinit
core :: FileWriter :: defaultinit
binary :: BinaryStream :: defaultinit
core :: Writer :: defaultinit
core :: Object :: defaultinit
core :: Stream :: defaultinit
core :: FileStream :: file_stat
The status of a file. see POSIX stat(2).core :: FileWriter :: from_fd
Creates a new File stream from a file descriptorcore :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: FileWriter :: is_writable=
core :: Stream :: last_error=
Error produced by the file streamcore :: Stream :: lookahead=
Lookahead buffer for codecscore :: Stream :: lookahead_capacity
Capacity of the lookaheadcore :: Stream :: lookahead_capacity=
Capacity of the lookaheadcore :: Stream :: lookahead_length
Current occupation of the lookaheadcore :: Stream :: lookahead_length=
Current occupation of the lookaheadcore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).core :: Writer :: serialize_msgpack
Serializevalue
in MessagePack format
core :: FileStream :: set_buffering_mode
Sets the buffering mode for the current FileStreamcore :: Writer :: write_block
Write the length as a 64 bits integer, then the content oftext
core :: Writer :: write_bool
Write a booleanvalue
on a byte, using 0 for false
and 1 for true
core :: Stream :: write_buffer
Buffer for writing data to a streamcore :: Stream :: write_buffer=
Buffer for writing data to a streamcore :: Writer :: write_bytes_from_cstring
Writelen
bytes from ns
core :: Writer :: write_double
Write a floating pointvalue
on 64 bits
core :: Writer :: write_int64
Writevalue
as a signed integer on 64 bits
core :: Writer :: write_msgpack_array
Write an array header forlen
items in the shortest possible MessagePack array format
core :: Writer :: write_msgpack_array16
Write an array header forlen
items, max of 0xFFFF items
core :: Writer :: write_msgpack_array32
Write an array header forlen
items, max of 0xFFFF_FFFF items
core :: Writer :: write_msgpack_bin
Writedata
in the shortest possible MessagePack bin format
core :: Writer :: write_msgpack_bin16
Writedata
in bin16 format, max of 0xFFFF bytes
core :: Writer :: write_msgpack_bin32
Writedata
in bin32 format, max of 0xFFFF_FFFF bytes
core :: Writer :: write_msgpack_bin8
Writedata
in bin8 format, max of 0xFF bytes
core :: Writer :: write_msgpack_bool
Writebool
in MessagePack format
core :: Writer :: write_msgpack_double
Writevalue
as a MessagePack double
core :: Writer :: write_msgpack_ext
Write an application-specific extension fortyp
and bytes
in the shortest possible MessagePack ext format
core :: Writer :: write_msgpack_ext16
Write the header for an application-specific extension oflen
data bytes
core :: Writer :: write_msgpack_ext32
Write the header for an application-specific extension oflen
data bytes
core :: Writer :: write_msgpack_ext8
Write the header for an application-specific extension oflen
data bytes
core :: Writer :: write_msgpack_fixarray
Write an array header forlen
items, max of 0x0F items
core :: Writer :: write_msgpack_fixext1
Write the header for an application-specific extension of one data bytecore :: Writer :: write_msgpack_fixext16
Write the header for an application-specific extension of 16 data bytescore :: Writer :: write_msgpack_fixext2
Write the header for an application-specific extension of two data bytescore :: Writer :: write_msgpack_fixext4
Write the header for an application-specific extension of 4 data bytescore :: Writer :: write_msgpack_fixext8
Write the header for an application-specific extension of 8 data bytescore :: Writer :: write_msgpack_fixint
Writevalue
as a single byte with metadata
core :: Writer :: write_msgpack_fixmap
Write a map header forlen
key/value pairs, max of 0x0F pairs
core :: Writer :: write_msgpack_fixstr
Writetext
in fixstr format, max of 0x1F bytes
core :: Writer :: write_msgpack_float
Writevalue
as a MessagePack float (losing precision)
core :: Writer :: write_msgpack_int
Write the integervalue
either as the shortest possible MessagePack int
core :: Writer :: write_msgpack_int16
Writevalue
over two signed bytes, following 1 metadata byte
core :: Writer :: write_msgpack_int32
Writevalue
over 4 signed bytes, following 1 metadata byte
core :: Writer :: write_msgpack_int64
Writevalue
over 8 signed bytes, following 1 metadata byte
core :: Writer :: write_msgpack_int8
Writevalue
over one signed byte, following 1 metadata byte
core :: Writer :: write_msgpack_map
Write a map header forlen
keys/value pairs in the shortest possible MessagePack map format
core :: Writer :: write_msgpack_map16
Write a map header forlen
key/value pairs, max of 0xFFFF pairs
core :: Writer :: write_msgpack_map32
Write a map header forlen
key/value pairs, max of 0xFFFF_FFFF pairs
core :: Writer :: write_msgpack_null
Writenull
, or nil, in MessagePack format
core :: Writer :: write_msgpack_str
Writetext
in the shortest possible MessagePack format
core :: Writer :: write_msgpack_str16
Writetext
in str16 format, max of 0xFFFF bytes
core :: Writer :: write_msgpack_str32
Writetext
in str32 format, max of 0xFFFF_FFFF bytes
core :: Writer :: write_msgpack_str8
Writetext
in str8 format, max of 0xFF bytes
core :: Writer :: write_msgpack_uint16
Writevalue
over two unsigned bytes, following 1 metadata byte
core :: Writer :: write_msgpack_uint32
Writevalue
over 4 unsigned bytes, following 1 metadata byte
core :: Writer :: write_msgpack_uint64
Writevalue
over 8 unsigned bytes, following 1 metadata byte
core :: Writer :: write_msgpack_uint8
Writevalue
over one unsigned byte, following 1 metadata byte
core :: FileWriter :: write_native
Writelen
bytes from native
.
# `Stream` that can write to a File
class FileWriter
super FileStream
super Writer
redef fun write_bytes_from_cstring(cs, len) do
if last_error != null then return
if not _is_writable then
last_error = new IOError("cannot write to non-writable stream")
return
end
write_native(cs, 0, len)
end
redef fun write(s)
do
if last_error != null then return
if not _is_writable then
last_error = new IOError("cannot write to non-writable stream")
return
end
s.write_native_to(self)
end
redef fun write_byte(value)
do
if last_error != null then return
if not _is_writable then
last_error = new IOError("Cannot write to non-writable stream")
return
end
if _file.as(not null).address_is_null then
last_error = new IOError("Writing on a null stream")
_is_writable = false
return
end
var err = _file.as(not null).write_byte(value)
if err != 1 then
# Big problem
last_error = new IOError("Problem writing a byte: {err}")
end
end
redef fun close
do
super
_is_writable = false
end
redef var is_writable = false
# Write `len` bytes from `native`.
private fun write_native(native: CString, from, len: Int)
do
if last_error != null then return
if not _is_writable then
last_error = new IOError("Cannot write to non-writable stream")
return
end
if _file.as(not null).address_is_null then
last_error = new IOError("Writing on a null stream")
_is_writable = false
return
end
var err = _file.as(not null).io_write(native, from, len)
if err != len then
# Big problem
last_error = new IOError("Problem in writing : {err} {len} \n")
end
end
# Open the file at `path` for writing.
init open(path: String)
do
_file = new NativeFile.io_open_write(path.to_cstring)
self.path = path
_is_writable = true
if _file.as(not null).address_is_null then
last_error = new IOError("Cannot open `{path}`: {sys.errno.strerror}")
is_writable = false
end
end
# Creates a new File stream from a file descriptor
init from_fd(fd: Int) do
self.path = ""
_file = fd.fd_to_stream(wipe_write)
_is_writable = true
if _file.as(not null).address_is_null then
last_error = new IOError("Error: Opening stream from file descriptor {fd} failed with '{sys.errno.strerror}'")
_is_writable = false
end
end
end
lib/core/file.nit:207,1--300,3