Menu

#1168 Archive Conversion [Command]

open
nobody
None
5
2014-12-12
2013-08-23
Matt Heyse
No

c (Convert) command

Converts one archive to another

I had been trying to convert archive types (from windows to unix) with the u command. but I recently found that I was wrong and that it was really wasn't doing the conversion. see Bug report #1365

What I would like to suggest is a way to do this. Either by increasing the functionality of the u command or adding a completely new one (I'll propose 'c' (Convert) for this example)

It would allow easy conversion from one archive [type] to another.

A new -c switch allows the conversion without overwriting the original archive (extensions will be different). -c{new_archive_name} allows the new archive name to be declared

By default the output archive is the same name as the input, replacing the original file. If the input archive type is derived from the file extension, the old extension is dropped and the new extension based off its type is added. Use of the -t{archive_type} switch prevents the old extension from being dropped.

Switches that are dual purpose (i.e. than can be used on input and output archives) can be differentiated by using -c-{switch} notation for the output archive. Plain -{switch} is for the input archive (but are inherited to the output archive, if not overridden). The Special switch -c-- prevents switch inheritance to the output archive.

Examples

7z c Old_Archive.zip

Converts the zip archive Old_Archive.zip to 7z format and renames it Old_Archive.7z
(7z currently assumes 7z type if not specified, .zip is dropped and adds .7z extension [-sas behavior])

7z c -c Old_Archive.zip

Same as above but both Old_Archive.zip still exists

7z c My.7z -c-tzip

Converts My.7z to a zip type archive renamed to My.zip

7z c Old_Archive.zip -cNewArchive.7z

Makes a new archive NewArchive.7z in 7z format from the archive Old_Archive.zip

7z c Old_Archive.zip -p1234 -cNewArchive.7z

Makes a new archive NewArchive.7z in 7z format protected by the password 1234 from the archive Old_Archive.zip that also had been protected with "1234"

7z c Old_Archive.zip -p1234 -cNewArchive.7z -c-pABCD

Makes a new archive NewArchive.7z in 7z format protected by the password ABCD from the archive Old_Archive.zip that had been protected with "1234"

7z c My.7z -p1234 -c-pABCD

While it does do a full conversion, the net effect is that My.7z was protected by "1234" but is now protected by "ABCD".

7z c My.7z -p1234 -c--

While it does do a full conversion, the net effect is that My.7z was protected by "1234" but is now not password protected.

7z c My.7z -v1m
7z c My.7z -c-v1m

Both do the Same exact thing, convert My.7z to a split archive of 1MB sized chunks. The -v switch is an output only switch so it does not need the -c-v notation and would be inherited normally. -c-v switch is allowed because if a -c-- switch is used the inheritance would be lost (i.e. 7z c My.7z -p1234 -c-- -c-v1m)

Discussion

  • Matt Heyse

    Matt Heyse - 2013-08-23

    Implementation notes


    Above is a functional overview of the 'Request', and it may sound complex, but I'm really just making all the operational assumptions that 7z currently does.

    Programmably at its simplest the 'c' Command is just two runs of 7z (a 'e' command and then a 'a' command just created directory tree.)

    With the following notes:

    for the 'e' Command run
    + ignore all -c options
    + make a temp_directory in the -w[dirpath] to extract into
    + if not -c{new_archive_name} and no -t{archive_type} a drop the extension from the old_archive name and append a new -c[old_archive-no-extension] to the 'a' command line
    + if still no -c{new_archive_name} switch append a new -c[old_archive] to the 'a' command line
    + if no -t{archive_type}, append -t{archive_type} (based on file name) to the 'a' command line
    * When extraction is complete, delete old_archive if no -c or -c{new_archive_name} is present

    for the 'a' Command run
    + if no -c-- switch is present copy all non -c switches to this run
    + if -c-- is present just drop it (don't want '--' to stick around
    + convert all the -c[stuff] switches to just [stuff]
    + + For all [stuff] that are single use switches (like -t{archive_type}) replace any on the command line
    + + For all [stuff] that are multi use switches (like -v{size}) just append to command line
    * When creation is complete delete the temp_directory.

    Of course a Virtual Memory file system or direct streaming of the 'e' Command to a 'a' Command would be better than using the disk. However they could be much more difficult depending on the current internals of 7z (of which I simply do not know).

     
  • bmn13

    bmn13 - 2013-09-12

    Shouldn't it be more like 'x' command & 'a' command so as to retain subdirectory information?

    Also regarding your last comment about "direct streaming" between the two commands being "better than using the disk", you could always pipe a -so over to a -si.


    i.e.
    7z c OriginalArchive.zip -pOriginalPassword -cNewArchive.7z -c-pNewPassword
    would effectively be
    7z x OriginalArchive -pOriginalPassword -so | 7z a -si NewArchive.7z -pNewPassword


    I like the idea of this feature & hope it gets implemented. ☺

     

    Last edit: bmn13 2013-09-12

Log in to post a comment.