Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 13, 2005 std.stream.File.available() always return 0 | ||||
---|---|---|---|---|
| ||||
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. |
August 13, 2005 Re: std.stream.File.available() always return 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shawn Liu | "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. |
August 13, 2005 Re: std.stream.File.available() always return 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shawn Liu | "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. |
August 13, 2005 Re: std.stream.File.available() always return 0 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | 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. > |
Copyright © 1999-2021 by the D Language Foundation