Menu

Logging when empty files are added to 7z archives

2017-08-15
2017-08-15
  • Paul Walker

    Paul Walker - 2017-08-15

    When compressing files into a 7z file from the command line, it doesn't show empty files in the log. They are being added into the archive just fine, but the log just doesn't show them. When compressing into a zip file, the log does show them. I'm using the -bb3 switch to turn on full logging - are there any other switches I can use to show the empty files have been added to the archive?

    This is using 7-Zip 16.04 64-bit on Windows 10

    7z Example

    1) Create a new directory

    PS C:\> New-Item c:\tst-7z -ItemType Directory
    
    
    
    
    
        Directory: C:\
    
    
    
    
    
    Mode                LastWriteTime         Length Name
    
    ----                -------------         ------ ----
    
    d-----       15/08/2017     17:15                tst-7z
    

    2) Create an empty file

    PS C:\> cd c:\tst-7z
    
    PS C:\tst-7z> New-Item -Name empty_file.txt -ItemType File
    
    
    
    
    
        Directory: C:\tst-7z
    
    
    
    
    
    Mode                LastWriteTime         Length Name
    
    ----                -------------         ------ ----
    
    -a----       15/08/2017     17:15              0 empty_file.txt
    

    3) Create a file with some data in it

    PS C:\tst-7z> New-Item -Name big_file.txt -ItemType File -Value "some content"
    
    
    
    
    
        Directory: C:\tst-7z
    
    
    
    
    
    Mode                LastWriteTime         Length Name
    
    ----                -------------         ------ ----
    
    -a----       15/08/2017     17:15             12 big_file.txt
    

    4) Create a 7z file. Note the switch -bb3 to turn on full logging, but only the file with data is shown as having been added to the archive

    PS C:\tst-7z> 7z a -bb3 tst.7z *
    
    
    
    7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04
    
    
    
    Scanning the drive:
    
    2 files, 12 bytes (1 KiB)
    
    
    
    Creating archive: tst.7z
    
    
    
    Items to compress: 2
    
    
    
    
    + big_file.txt
    
    
    
    Files read from disk: 1
    
    Archive size: 189 bytes (1 KiB)
    
    Everything is Ok
    

    5) List the archive file - note that the empty file has been added to the archive OK

    PS C:\tst-7z> 7z l tst.7z
    
    
    
    7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04
    
    
    
    Scanning the drive for archives:
    
    1 file, 189 bytes (1 KiB)
    
    
    
    Listing archive: tst.7z
    
    
    
    --
    
    Path = tst.7z
    
    Type = 7z
    
    Physical Size = 189
    
    Headers Size = 173
    
    Method = LZMA2:12
    
    Solid = -
    
    Blocks = 1
    
    
    
       Date      Time    Attr         Size   Compressed  Name
    
    ------------------- ----- ------------ ------------  ------------------------
    
    2017-08-15 17:15:10 ....A            0            0  empty_file.txt
    
    2017-08-15 17:15:10 ....A           12           16  big_file.txt
    
    ------------------- ----- ------------ ------------  ------------------------
    
    2017-08-15 17:15:10                 12           16  2 files
    

    Zip Example

    1) Create a new directory

    PS C:\> New-Item c:\tst-zip -ItemType Directory
    
    
    
    
    
        Directory: C:\
    
    
    
    
    
    Mode                LastWriteTime         Length Name
    
    ----                -------------         ------ ----
    
    d-----       15/08/2017     17:14                tst-zip
    

    2) Create an empty file

    PS C:\> cd c:\tst-zip
    
    PS C:\tst-zip> New-Item -Name empty_file.txt -ItemType File
    
    
    
    
    
        Directory: C:\tst-zip
    
    
    
    
    
    Mode                LastWriteTime         Length Name
    
    ----                -------------         ------ ----
    
    -a----       15/08/2017     17:14              0 empty_file.txt
    

    3) Create a file with some data in it

    PS C:\tst-zip> New-Item -Name big_file.txt -ItemType File -Value "some content"
    
    
    
    
    
        Directory: C:\tst-zip
    
    
    
    
    
    Mode                LastWriteTime         Length Name
    
    ----                -------------         ------ ----
    
    -a----       15/08/2017     17:14             12 big_file.txt
    

    4) Create a zip file. Note the switch -bb3 to turn on full logging. This time, both files are shown as having been added to the archive

    PS C:\tst-zip> 7z a -bb3 tst.zip *
    
    
    
    7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04
    
    
    
    Scanning the drive:
    
    2 files, 12 bytes (1 KiB)
    
    
    
    Creating archive: tst.zip
    
    
    
    Items to compress: 2
    
    
    
    
    + big_file.txt
    
    
    + empty_file.txt
    
    
    
    Files read from disk: 2
    
    Archive size: 310 bytes (1 KiB)
    
    Everything is Ok
    

    5) List the archive file - note that the empty files are again both in the archive

    PS C:\tst-zip> 7z l tst.zip
    
    
    
    7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04
    
    
    
    Scanning the drive for archives:
    
    1 file, 310 bytes (1 KiB)
    
    
    
    Listing archive: tst.zip
    
    
    
    --
    
    Path = tst.zip
    
    Type = zip
    
    Physical Size = 310
    
    
    
       Date      Time    Attr         Size   Compressed  Name
    
    ------------------- ----- ------------ ------------  ------------------------
    
    2017-08-15 17:14:06 ....A           12           12  big_file.txt
    
    2017-08-15 17:14:06 ....A            0            0  empty_file.txt
    
    ------------------- ----- ------------ ------------  ------------------------
    
    2017-08-15 17:14:06                 12           12  2 files
    
     
  • Igor Pavlov

    Igor Pavlov - 2017-08-15

    it's not simple to fix it.
    7z archive uses special records for empty files.
    So 7Z.dll doesn't request the data for empty files from 7z.exe.
    if we requst the data, data can be non-empty. So we can't use special records anymore. And we need another code for them.

     
  • Paul Walker

    Paul Walker - 2017-08-15

    I obviously have no idea how it works, but either at the point it looks at the file and decides it's empty, or wherever it uses the special record, might it be possible to add a note into the log? It's handling the files fine from what I can see, it would just be handy to have these empty files mentioned in the output, even if it's a separate section at the end etc

    Never mind if not, I might just have to use zip files for this particular use-case.

    Thanks

     

Log in to post a comment.

MongoDB Logo MongoDB