rv799cv has asked for the wisdom of the Perl Monks concerning the following question:

hi, if you change the extension of a .docx file to a .zip and extract the zip file you can modify the file without opening word.

if this .docx file is in SharePoint then doing this will remove the version history coz if you copy a SharePoint file you will lose its history unless you move it.

Is there an example of how to modify a zipped file without writing it into disk! modifying in memory in windows environment?

Thanks for your help

Replies are listed 'Best First'.
Re: Modify zip file in memory
by Corion (Patriarch) on May 17, 2014 at 13:58 UTC

    You will have to do your modification in two steps:

    1. Write your changed version to a new file
    2. Overwrite the original file with your changed version

    Also, I think that Sharepoint automatically inserts markers into files that look like (zipped) XML to track whether a file was copied/renamed and still reference the history.

Re: Modify zip file in memory
by zentara (Cardinal) on May 17, 2014 at 14:14 UTC

      thanks so much for the reply! would any of you have an small example that can lead me?

        I don't have Windows, but after googling a bit, it looks like IO::Uncompress::Unzip and IO::Compress::Zip does what you want from a high level interface. That will save you the trouble of dealing with IO::Scalar manually unzipping and tracking position. There are examples in the docs.

        Also see using IO::String instead of IO::Scalar for in memory zip files.

        With IO::Scalar, the basic example is:

        use IO::Scalar; my $memory_file = ''; #scalar as a file , my $memfile_fh = IO::Scalar->new(\$memory_file); #filehandle to the sc +alar # write to the scalar $memory_file my $status = $zip->writeToFileHandle($memfile_fh); $memfile_fh->close;
        Googling around I found this for Windows. Chilcat zip utility which claims to do in memory access in Windows.

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh