iopipe code to count lines in gzipped file works with v 0.1.7 but fails with 0.2.1

Andrew aabrown24 at hotmail.com
Fri Aug 7 13:40:46 UTC 2020


Hi,

This code to count lines in a gzipped file exits with "Program 
exited with code -9" when run with the latest version of the 
library, I guess because I am doing unsafe things. Could someone 
tell me how to change it to make it work? The actual program I'm 
writing processes a file line by line, so ideally I'd like to 
keep the structure of open a file, then foreach over it.

Thanks very much

Andrew

/+ dub.sdl:
	name "hello"
	dependency "iopipe" version="~>0.2.0"
+/

import std.stdio;
import std.typecons;
import iopipe.textpipe;
import iopipe.zip;
import iopipe.bufpipe;
import std.io : File = File;

void main()
{
   auto counter = 0;
   auto fileToRead = 
File("file.gz").refCounted.bufd.unzip(CompressionFormat.gzip);

   foreach (line; fileToRead.assumeText.byLineRange!false)
   {
     counter++;
   }

   writeln(counter);
}



More information about the Digitalmars-d-learn mailing list