Function magicFileReader
Reads magic file contents and push magic entries to sink.
void magicFileReader(OutRange)
(
const(void)[] data,
OutRange sink
)
if (isOutputRange!(OutRange, MagicEntry));
Throws
MimeMagicFileException
on error.
Example
auto data =
"MIME-Magic\0\n[60:text/x-diff]\n" ~
">0=__NOMAGIC__\n" ~
"0>4=\x00\x02\x55\x40&\xff\xf0~2+8\n" ~
"1>12=\x00\x04\x55\x40\xff\xf0~4+10\n";
void sink(MagicEntry t) {
assert(t .mimeType == "text/x-diff");
assert(t .magic .weight == 60);
assert(t .magic .matches .length == 1);
assert(t .deleteMagic);
auto match = t .magic .matches[0];
assert(match .startOffset == 4);
assert(match .value .length == 2);
assert(match .mask .length == 2);
assert(match .type == MagicMatch .Type .host16);
assert(match .rangeLength == 8);
assert(match .submatches .length == 1);
auto submatch = match .submatches[0];
assert(submatch .startOffset == 12);
assert(submatch .value .length == 4);
assert(!submatch .hasMask());
assert(submatch .type == MagicMatch .Type .host32);
assert(submatch .rangeLength == 10);
}
magicFileReader(data, &sink);
void emptySink(MagicEntry t) {
}
assertThrown!MimeMagicFileException(magicFileReader("MIME-wrong-magic", &emptySink));