Splitting up large dirty file
drug
drug2004 at bk.ru
Wed May 16 08:20:06 UTC 2018
16.05.2018 10:06, Dennis пишет:
>
> Here's a version that only outputs the first chunk:
> ```
> import std.stdio;
> import std.range;
> import std.algorithm;
> import std.file;
> import std.exception;
>
> void main(string[] args) {
> enforce(args.length == 2, "Pass one filename as argument");
> auto lineChunks = File(args[1],
> "r").byLine.drop(4).chunks(10_000_000/10);
> new File("output.txt", "w").write(lineChunks.front.joiner);
> }
> ```
>
> dmd splitFile -g
> ./splitFile.exe UTF-8-test.txt
>
> std.utf.UTFException at C:\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(1380):
> Invalid UTF-8 sequence (at index 4)
> ----------------
> 0x004038D2 in pure dchar std.utf.decodeImpl!(true, 0,
> char[]).decodeImpl(ref char[], ref uint) at
> C:\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(1529)
> 0x00403677 in pure @trusted dchar std.utf.decode!(0, char[]).decode(ref
> char[], ref uint) at C:\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(1076)
> 0x00403575 in pure @property @safe dchar
> std.range.primitives.front!(char).front(char[]) at
> C:\D\dmd2\windows\bin\..\..\src\phobos\std\range\primitives.d(2333)
> 0x0040566D in pure @property dchar
> std.algorithm.iteration.joiner!(std.range.Chunks!(std.stdio.File.ByLineImpl!(char,
> char).ByLineImpl).Chunks.Chunk).joiner(std.range
> .Chunks!(std.stdio.File.ByLineImpl!(char,
> char).ByLineImpl).Chunks.Chunk).Result.front() at
> C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\iteration.d(2491)
What is the purpose of `.drop(4)`? I'm pretty sure this is the reason of
the exception.
More information about the Digitalmars-d-learn
mailing list