Record separator is being lost after string cast

Kadir Erdem Demir via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 4 00:13:28 PST 2015


I am opening a .gz file and reading it chunk by chunk for 
uncompressing it.

The data in the uncompressed file is like : aRSbRScRSd, There are 
record separators(ASCII code 30) between each record(records in 
my dummy example a,b,c).

     File file = File(mylog.gz, "r");
     auto uc = new UnCompress();
     foreach (ubyte[] curChunk; file.byChunk(4096*1024))
     {
         auto uncompressed = cast(string)uc.uncompress(curChunk);
         writeln(uncompressed);
         auto stringRange = uncompressed.splitLines();
         foreach (string line; stringRange)
         {
             ***************** Do something with line

The result of the code above is: abcd unfortunately record 
separators(ASCII 30) are missing.

I realized by examining the data record separators are missing 
after I cast ubyte[] to string.

Now I have two questions :

Urgent one (my boss already a little disturbed I started the task 
with D I need to solve this): What should I change in the code to 
keep record separator?

Second one : How can I write the code above without for loops? I 
want to read gz file line by line.

A more general and understandable code for first question :

     ubyte[] temp = [ 65, 30, 66, 30, 67];
     writeln(temp);
     string tempStr = cast(string) temp;
     writeln (tempStr);

Result is : ABC which is not desired.

Thanks
Kadir Erdem


More information about the Digitalmars-d-learn mailing list