Treat memory as a file with a name.
Steve Teale
steve.teale at britseyeview.com
Fri Feb 21 23:26:24 PST 2014
This is probably not exactly a D question.
The library librsvg expects to get an SVG file filename. I have
the data of such a file in memory.
How do I dress up that memory as a file with a name so that I can
pass the name to the librsvg open function.
I've looked at std.mmfile, and played with it, giving a name to
the constructor, along with the address and size of my memory
block.
import std.mmfile;
import std.stdio;
import std.stream;
void main()
{
char[] ca;
ca.length = 100000;
ca[] = 'X';
MmFile mmf = new MmFile("glob", 0, 100000UL, ca.ptr);
std.stream.File sf = new std.stream.File("glob", FileMode.In);
char[] b;
b.length = 20;
sf.readExact(b.ptr, 20);
writefln("%s", b);
}
But then I just get 'No such file or directory', which is what
I'd expect after I'd taken the trouble to read mmfile.d.
I had expected it to create a stub entry in the file system or
something, and the somehow use fmemopen(), but it just looks for
an existing file.
At the moment I'm having to write the data to a temporary file,
and then pass the name of the temp to rsvg.
There must be some elegant way to do this!
More information about the Digitalmars-d-learn
mailing list