www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3868] New: It would be nice to have a function which read a file lazily using a range

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3868

           Summary: It would be nice to have a function which read a file
                    lazily using a range
           Product: D
           Version: 2.040
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmail.com


--- Comment #0 from Jonathan M Davis <jmdavisProg gmail.com> 2010-03-01
23:13:24 PST ---
It would be great if there were a function which returned a range to a file,
reading it in as you moved through the range. Presumably, it would do some
buffering, but it wouldn't be a case of reading in the whole file at a time and
hopefully would be more friendly and powerful than reading in a single byte, or
int, or whatever like you'd do with read() with streams. It also avoids having
to explicitly read in a portion of the file at a time like you'd do with
readBlock(). In addition, it would make it possible to use various of the
standard algorithms directly on files.

It might also be useful to write to a file with a range, but I'm not acquainted
well enough with output ranges to know how well it would work, or if it would
be as useful as reading with ranges. It would probably be useful though.

In any case, I really like the idea of being to read a file with a range. Maybe
there's a reason that I'm not aware of which would make it a really bad idea,
but I think that it would be a good addition to phobos.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 01 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3868


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha yahoo.com


--- Comment #1 from David Simcha <dsimcha yahoo.com> 2010-08-19 19:14:53 PDT ---
Shouldn't std.stdio.File.byChunk() do this?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 19 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3868


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com


--- Comment #2 from Andrei Alexandrescu <andrei metalanguage.com> 2010-08-19
21:08:24 PDT ---
byChunk uses opApply. We need to transform it into a range; using opApply alone
severely limits the applicability of byChunk.

Here's a nice potential application of byChunk:

import std.stdio;
void main(string[] a) {
    enforce(a.length == 3);
    auto f1 = File(a[1]), f2 = File(a[2]);
    immutable bufsize = 1024 * 1024;
    return equal(f1.byChunk(bufsize), f2.byChunk(bufsize));
}

One other idea suggested by the above is to implement the algorithm found in
diff in std.algorithm. Then we can write a diff program in a dozen line of
code, using general components.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 19 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3868


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011