Author: Tomas Rutkauskas
I'm having an issue converting a Unix 1.15 GB text file to a Windows file. It
always seems my application runs out of memory during the conversion. Does anyone
have any ideas as to how to accomplish this?
Answer:
It sounds like you're trying to read the whole file into memory or something. How
does this work:
1 program unix2dos;
2 3 {$APPTYPE CONSOLE}4 5 uses6 SysUtils;
7 8 var9 fp1: file;
10 fp2: TextFile;
11 buffer, buf2: array[1..8192] of Char;
12 numread: Integer;
13 i: Integer;
14 begin15 if paramcount <> 2 then16 begin17 writeln('USAGE : UNIX2DOS <input file> <output file>');
18 writeln(' Takes UNIX text file (linefeed delimited) and');
19 writeln(' converts it to a DOS (CR/LF) delimited text file.');
20 halt(10);
21 end;
22 if FileExists(Paramstr(1)) then23 begin24 AssignFile(fp1, paramstr(1));
25 Reset(fp1, 1);
26 AssignFile(fp2, paramstr(2));
27 SetTextBuf(fp2, buf2);
28 rewrite(fp2);
29 repeat30 BlockRead(fp1, buffer, sizeof(buffer), Numread);
31 if Numread <> 0 then32 begin33 for i := 1 to Numread do34 begin35 if buffer[i] = #10 then36 writeln(fp2)
37 else38 write(fp2, buffer[i]);
39 end;
40 end;
41 until42 NumRead = 0;
43 close(fp1);
44 close(fp2);
45 end46 else47 writeln('Could not find file : ', paramstr(1));
48 end.