phobos: What type to use instead of File when doing I/O on streams?

2015-11-08 Thread J.Frank via Digitalmars-d-learn
Hello again, I'm a bit puzzled by the "File" type. Looking at the implementation, it seems that all I/O functions were stuffed into a single class^H^H^H^H^Hstruct. What I expected to find is some kind of "Stream" class (with read(), write(), eof()), which is extended by a "File" class (with s

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-08 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 8 November 2015 at 20:47:08 UTC, J.Frank wrote: Hello again, I'm a bit puzzled by the "File" type. Looking at the implementation, it seems that all I/O functions were stuffed into a single class^H^H^H^H^Hstruct. What I expected to find is some kind of "Stream" class (with read(), w

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-08 Thread J.Frank via Digitalmars-d-learn
On Sunday, 8 November 2015 at 21:57:55 UTC, Alex Parrill wrote: Post what you're trying to do if you want an example. $ cat test.d import std.stdio; //void foo(Stream in_stream, Stream out_stream) // I want something like this void foo(File in_stream, File out_stream) { in_stream.see

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 8 November 2015 at 20:47:08 UTC, J.Frank wrote: So, assuming my program reads from stdin and is supposed to work on a file as well as on a pipe (which is not seekable) - how can I make the compiler bark when I accidently use stdin.seek()? You don't, in general. stdin is sometimes s

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
On Sunday, 8 November 2015 at 23:50:58 UTC, Adam D. Ruppe wrote: You don't, in general. stdin is sometimes seekable and the compiler doesn't know if it is or not until you try at runtime. Hm. "Maybe the stream is seekable, maybe it is not" is not really an option for a language that is suppose

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
My question is now: How can I make this work without using deprecated stuff? import std.cstream; void foo(InputStream in_stream, OutputStream out_stream) { // in_stream.seek(3); // compile error - good :) char[] line; while ((line = in_stream.readLine()) !is null)

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Ali Çehreli via Digitalmars-d-learn
On 11/09/2015 01:48 AM, J.Frank wrote: My question is now: How can I make this work without using deprecated stuff? import std.cstream; void foo(InputStream in_stream, OutputStream out_stream) { //in_stream.seek(3); // compile error - good :) char[] line; while ((line = in_strea

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
On Monday, 9 November 2015 at 14:48:35 UTC, Ali Çehreli wrote: import std.stdio; import std.range; void foo(I, O)(I in_stream, O out_stream) if (isInputRange!I && isOutputRange!(O, ElementType!I)) { // in_stream.seek(3); // compile error - good :) foreach (element;

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 9 November 2015 at 18:18:19 UTC, J.Frank wrote: On Monday, 9 November 2015 at 14:48:35 UTC, Ali Çehreli wrote: import std.stdio; import std.range; void foo(I, O)(I in_stream, O out_stream) if (isInputRange!I && isOutputRange!(O, ElementType!I)) { // in_stream

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Ali Çehreli via Digitalmars-d-learn
On 11/09/2015 10:18 AM, J.Frank wrote: On Monday, 9 November 2015 at 14:48:35 UTC, Ali Çehreli wrote: import std.stdio; import std.range; void foo(I, O)(I in_stream, O out_stream) if (isInputRange!I && isOutputRange!(O, ElementType!I)) { // in_stream.seek(3); // compile

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
On Monday, 9 November 2015 at 18:44:00 UTC, Alex Parrill wrote: Ranges are streams. file.byLine(Copy) and byChunk are effectively streams that are ranges. I might be wrong, but from what I read so far I don't think that "ranges are streams": - Can you read an arbitrary length of bytes from a

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread J.Frank via Digitalmars-d-learn
On Monday, 9 November 2015 at 19:38:06 UTC, Ali Çehreli wrote: As far as I understand, the issue is to prevent the seek() call at compile time, right? If so, the range types that byLine() and byLineCopy() return does not have such a member function. I think the code achieves that goal because

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 9 November 2015 at 19:49:15 UTC, J.Frank wrote: I'm looking for a replacement for the deprecated inferfaces InputStream and OutputStream. Just keep using them. The deprecated note isn't really important... they will still be in Phobos for another year and you can copy the file out

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 9 November 2015 at 19:42:53 UTC, J.Frank wrote: (BTW. Where do I find select()/poll() in phobos?) They are in `core.sys.posix.sys.select` In general, OS headers for Posix in C like "sys/select.h" can be gotten by "import core.sys.posix.sys.select;" is in "core.sys.posix.unistd"

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 9 November 2015 at 08:49:08 UTC, J.Frank wrote: Hm. "Maybe the stream is seekable, maybe it is not" is not really an option for a language that is supposed to be type safe. It just isn't known at compile time. Files, especially on Unix, are interchangeable at compile time but offer

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-09 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 9 November 2015 at 19:42:53 UTC, J.Frank wrote: On Monday, 9 November 2015 at 18:44:00 UTC, Alex Parrill wrote: Ranges are streams. file.byLine(Copy) and byChunk are effectively streams that are ranges. I might be wrong, but from what I read so far I don't think that "ranges are st

Re: phobos: What type to use instead of File when doing I/O on streams?

2015-11-10 Thread Kagamin via Digitalmars-d-learn
On Monday, 9 November 2015 at 19:42:53 UTC, J.Frank wrote: - Can you flush() a range? - Can you use select() on a range? Maybe you should factor out a function that does pure data processing on arbitrary ranges and manage sources of the ranges - opening, flushing and closing files - in the c