Canonical/Idiomatic in memory files
Jonathan M Davis
jmdavisProg at gmx.com
Tue May 28 22:41:37 PDT 2013
On Wednesday, May 29, 2013 05:47:55 Russel Winder wrote:
> On Tue, 2013-05-28 at 13:46 -0400, Jonathan M Davis wrote:
> […]
>
> > Do you mean something like std.mmfile.MmFile which operates on a file as
> > an
> > array in memory using mmap, or do you mean operating on memory that has no
> > connection to a file at all (in which case, I'm not sure why you'd want to
> > use File)? If the former, well use std.file.MmFile. If the latter, I
> > expect that you're out of luck. Unfortunately, std.stdio.File is
> > currently just a wrapper around FILE and is thus limited by what you can
> > do with FILE - that and I don't think that the File API took into
> > consideration the possibility of operating on anything other than an
> > actual file (and I honestly don't know what you'd be trying to do with it
> > where it would make any sense for to operate on anything other than an
> > actual file).
>
> Looks like I am out of luck then. :-(
>
> The context is writing a small program that can be a filter or operate
> on files: actually it is the wc program. So it needs to work with opened
> files and stdin. That is fine (sort of). The issue comes when writing
> unit tests for the code: unit tests should not touch the file system, so
> I need a memory buffer backed std.stdio.File for the tests. A mock file
> in a sense.As noted earlier Go, Python, all JVM languages have such
> things, and it really needs to be part of D. If there really is nothing
> like this, I should add a JIRA issue and see if I can create a pull
> request later in the summer.
A replacement for std.stdio is in the works, and it will likely have this sort
of thing in it (certainly, it will have the stuff necessary for enabling
streams and the like for std I/O). Unfortunately, the person who is working on
it has been very busy, so it's not ready yet. But there's no question that we
want to overhaul std.stdio. And part of that effort will be adding the stuff
which will replace the various stream modules in Phobos.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list