[Haskell-cafe] Re: Efficient way to edit a file

Bulat Ziganshin bulat.ziganshin at gmail.com
Tue Jun 20 05:20:23 EDT 2006


Hello Maurício,

Tuesday, June 20, 2006, 12:59:47 AM, you wrote:

>>>>>  I need to edit big text files (5 to 500 Mb). But I just need to
>>>>>change one or two small lines, and save it. What is the best way to do 
>>>>>that in Haskell, without creating copies of the whole files?
>    I like very much the idea of memory mapping the file. In some
> situations, random access to the file would help a lot. Can I do that on
> Windows?

i wanted to write what my Streams 0.2 library (see previous letter)
also supports memory-mapped files on Windows (see Examples/wc4MMFile.hs),
but i'm not sure what you really need it. if your edit don't involve
moving of data (i.e. new lines will have the same size as overwritten
ones), you don't need to use mmfile because it's enough to open file
in ReadWriteMode (see "openBinaryFile" call description). if you need
to change file size, then you can just read it into large buffer,
change all that you want and write it back.


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list