digitalmars.D - std.stream.File.available() always return 0
- Shawn Liu (4/4) Aug 13 2005 The Stream.available() method should be overrided in File class.
- Ben Hinkle (12/16) Aug 13 2005 And what should it return? Remember available() returns the number of by...
- Ben Hinkle (12/16) Aug 13 2005 How about this in std.stream.File:
- Shawn Liu (2/21) Aug 13 2005
The Stream.available() method should be overrided in File class. Otherwise it always return 0. I saw this method has been overrided in BufferedStream, EndianStream, TArrayStream and SliceStream.
Aug 13 2005
"Shawn Liu" <liuxuhong.cn gmail.com> wrote in message news:ddkfrn$2msg$1 digitaldaemon.com...The Stream.available() method should be overrided in File class. Otherwise it always return 0. I saw this method has been overrided in BufferedStream, EndianStream, TArrayStream and SliceStream.And what should it return? Remember available() returns the number of bytes available for "immediate" reading without blocking. I'm not aware of OS functions that return that information for system file handles. Note the definition of available is somewhat fuzzy since the meaning of "immediate" isn't exactly well defined. The only idea that comes to mind is to say that all seekable Files have whatever remains from the current position to the end of the file and if it isn't seekable it has 0 available (since it's probably a pipe). Note the original intent of available() was to ask streams that buffer how much is left in the buffer.
Aug 13 2005
"Shawn Liu" <liuxuhong.cn gmail.com> wrote in message news:ddkfrn$2msg$1 digitaldaemon.com...The Stream.available() method should be overrided in File class. Otherwise it always return 0. I saw this method has been overrided in BufferedStream, EndianStream, TArrayStream and SliceStream.How about this in std.stream.File: override size_t available() { if (seekable) { ulong lavail = size - position; if (lavail > size_t.max) lavail = size_t.max; return cast(size_t)lavail; } return 0; } That will assume reading the rest of the known file is available.
Aug 13 2005
I think this is reasonable. Thanks! "Ben Hinkle" <ben.hinkle gmail.com> wrote:ddktdd$31kf$1 digitaldaemon.com..."Shawn Liu" <liuxuhong.cn gmail.com> wrote in message news:ddkfrn$2msg$1 digitaldaemon.com...The Stream.available() method should be overrided in File class. Otherwise it always return 0. I saw this method has been overrided in BufferedStream, EndianStream, TArrayStream and SliceStream.How about this in std.stream.File: override size_t available() { if (seekable) { ulong lavail = size - position; if (lavail > size_t.max) lavail = size_t.max; return cast(size_t)lavail; } return 0; } That will assume reading the rest of the known file is available.
Aug 13 2005