digitalmars.D.learn - reading from a ubyte[] | byte[] as if from a stream? (Phobos)
- Charles Hixson <charleshixsn earthlink.net> Sep 18 2008
- BCS <ao pathlink.com> Sep 18 2008
- Tomas Lindquist Olsen <tomas famolsen.dk> Sep 18 2008
- Charles Hixson <charleshixsn earthlink.net> Sep 18 2008
- Tomas Lindquist Olsen <tomas famolsen.dk> Sep 18 2008
Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.
Sep 18 2008
Reply to Charles,Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.
MemoryStream http://www.digitalmars.com/d/1.0/phobos/std_stream.html
Sep 18 2008
BCS wrote:Reply to Charles,Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.
MemoryStream http://www.digitalmars.com/d/1.0/phobos/std_stream.html
From what I read, MemoryStream copies, TArrayStream does not Not sure what's wanted here though :)
Sep 18 2008
Tomas Lindquist Olsen wrote:BCS wrote:Reply to Charles,Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.
MemoryStream http://www.digitalmars.com/d/1.0/phobos/std_stream.html
From what I read, MemoryStream copies, TArrayStream does not Not sure what's wanted here though :)
TArrayStream would be what I want, except that it seems to require that the compilation be in release mode. I'm going to need to study just what that means. But if it isn't what's needed, then MemoryStream seems a reasonable alternative. (My suspicion is that it only constructs an array of bytes of memory if you don't pass it a buffer...but I haven't checked. The documentation sure seems to say that it copies the buffer.)
Sep 18 2008
Charles Hixson wrote:Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.
Now, I don't use phobos, but I think you're looking for std.stream.TArrayStream something like: --- auto data = new ubyte[1024]; auto str = new TArrayStream!(ubyte[])(data); ubyte ub; str.read(ub); --- HTH
Sep 18 2008









Charles Hixson <charleshixsn earthlink.net> 