removed require to define available, tell, seek in ioLib

This commit is contained in:
Onran 2026-06-22 14:47:58 +09:00
parent 21019e6737
commit 82da7e907d
5 changed files with 20 additions and 45 deletions

View file

@ -98,10 +98,6 @@ function lib.tell(descriptor)
return positions[descriptor] return positions[descriptor]
end end
function lib.flush(descriptor)
requireDescriptor(descriptor)
end
function lib.available(descriptor) function lib.available(descriptor)
requireDescriptor(descriptor) requireDescriptor(descriptor)

View file

@ -60,18 +60,6 @@ function lib.write(fd, bytearray)
end end
end end
function lib.seek(fd, mode, offset)
error("cannot seek the named pipe")
end
function lib.tell(fd)
error("cannot tell the named pipe")
end
function lib.flush(fd)
-- no flush on unix
end
function lib.available(fd) function lib.available(fd)
if fd == nil or fd < 0 then return 0 end if fd == nil or fd < 0 then return 0 end

View file

@ -97,14 +97,6 @@ function lib.write(handle, bytearray)
end end
end end
function lib.seek(handle, mode, offset)
error("cannot seek the named pipe")
end
function lib.tell(handle)
error("cannot tell the named pipe")
end
function lib.flush(handle) function lib.flush(handle)
C.FlushFileBuffers(handle) C.FlushFileBuffers(handle)
end end

View file

@ -32,18 +32,6 @@ function lib.write(descriptor, data)
sockets[descriptor]:send(data) sockets[descriptor]:send(data)
end end
function lib.seek(descriptor, mode, offset)
error("cannot seek socket")
end
function lib.tell(descriptor)
error("cannot tell socket")
end
function lib.flush(descriptor)
requireDescriptor(descriptor)
end
function lib.available(descriptor) function lib.available(descriptor)
requireDescriptor(descriptor) requireDescriptor(descriptor)

View file

@ -47,15 +47,14 @@ binaryMode - if enabled, most methods will expect bytes instead of strings
ioLib - I/O library. Should include the following functions: ioLib - I/O library. Should include the following functions:
read(descriptor: int, length: int) -> Bytearray read(descriptor: int, length: int) -> Bytearray
May return bytearray with a smaller size if bytes have not arrived yet or have run out May return bytearray with a smaller size if bytes have not arrived yet or have run out
May throw error if descriptor isn't readable
write(descriptor: int, data: Bytearray) write(descriptor: int, data: Bytearray)
seek(descriptor: int, mode: string, offset: int) May throw error if descriptor isn't writeable
[optional] seek(descriptor: int, mode: string, offset: int)
Mode may be 'b' (relative begin), 'c' (relative current), 'e' (relative end + 1) Mode may be 'b' (relative begin), 'c' (relative current), 'e' (relative end + 1)
May throw error if environment is not support seek [optional] tell(descriptor: int) -> int
tell(descriptor: int) -> int [optional] flush(descriptor: int)
May throw error if environment is not support tell [optional] available(descriptor: int) -> int
flush(descriptor: int)
available(descriptor: int) -> int
May return 0 if environment is not support available method
is_alive(descriptor: int) -> bool is_alive(descriptor: int) -> bool
close(descriptor: int) close(descriptor: int)
--]] --]]
@ -135,7 +134,7 @@ function io_stream:available(length)
available = #self.readBuffer available = #self.readBuffer
else else
available = self.ioLib.available(self.descriptor) available = self.ioLib.available and self.ioLib.available(self.descriptor) or 0
end end
if not length then if not length then
@ -388,10 +387,18 @@ function io_stream:write(arg, ...)
end end
function io_stream:seek(mode, offset) function io_stream:seek(mode, offset)
if not self.ioLib.seek then
error("cannot seek this stream")
end
self.ioLib.seek(self.descriptor, mode, offset) self.ioLib.seek(self.descriptor, mode, offset)
end end
function io_stream:tell() function io_stream:tell()
if not self.ioLib.tell then
error("cannot tell this stream")
end
return self.ioLib.tell(self.descriptor) return self.ioLib.tell(self.descriptor)
end end
@ -418,7 +425,11 @@ function io_stream:flush()
self.writeBuffer:clear() self.writeBuffer:clear()
end end
if self.flushMode ~= FLUSH_MODE_ONLY_BUFFER then self.ioLib.flush(self.descriptor) end if self.flushMode ~= FLUSH_MODE_ONLY_BUFFER then
if self.ioLib.flush then
self.ioLib.flush(self.descriptor)
elseif self:is_closed() then error("stream is closed") end
end
end end
return io_stream return io_stream