1

I want to solve a problem (which you can read about here as I don't feel like this should be part of the question).

So this is what I came up with:

$ tar -cO Templates | 7z a -si -mx=3 -p /t/out.tar.7z

I'm using the Templates folder on my computer so I can test it on a very small amount of data first.

And it works just as expected.

However, when I want to create a checksum of it, it fails:

$ tar -cO Templates | 7z a -si -so -mx=3 -p | tee /t/out.tar.7z | sha256sum

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,8 CPUs)


Error:
Incorrect command line
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  -

I noticed that when I execute what's in the first block of code, the tar ball inside the 7zip archive is called out.tar. In fact, that's why I let it end in .tar.7z: So the tar ball's name ends in .tar.

So maybe I should still include the file name, especially because the entire synopsis of the 7z command in its man page is:

7z [adeltux] [-] [SWITCH] <ARCHIVE_NAME> <ARGUMENTS>...

Unfortunately, this doesn't work either:

$ tar -cO Templates | 7z a -si -so -mx=3 -p out.tar.7z | tee /t/out.tar.7z | sha256sum

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,8 CPUs)
Creating archive stdout


Enter password (will not be echoed) :
Verify password (will not be echoed) :


System error:
E_NOTIMPL                
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  -

It doesn't even work if I explicitly state the archive type:

$ tar -cO Templates | 7z a -si -so -mx=3 -p -t7z | tee /t/out.tar.7z | sha256sum

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,8 CPUs)


Error:
Incorrect command line
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  -

  

$ tar -cO Templates | 7z a -si -so -mx=3 -p -t7z out.tar.7z | tee /t/out.tar.7z | sha256sum

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,8 CPUs)
Creating archive stdout


Enter password (will not be echoed) :
Verify password (will not be echoed) :


System error:
E_NOTIMPL                
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  -

How do I solve this? Writing the data to its destination and then hashing that file is not an option. I need the data to be encrypted.

  • @DopeGhoti The man page says this about the -so switch: Write data to StdOut (eg: % echo foo | 7z a dummy -tgzip -si -so > /dev/null) What else is it going to write to stdout if not the archive. Regarding your proposal: Doesn't work for me. I specifically mentioned this in the last sentence of my question. – UTF-8 Jun 15 '17 at 22:32
  • Yes, I see that now. – DopeGhoti Jun 15 '17 at 22:33
  • I'm confused. You create a /t/out.tar.7z file that you could hashsum, but you later say that you don't want to write the file for later hashing. – Jeff Schaller Jun 15 '17 at 23:41
  • @JeffSchaller I do want to store the archive. But I don't want to compute the hash from data read from the disk. Not only would this require an additional read of the entire archive, doubling the amount of time it takes to create it and its checksum, but what's way more important: I'd have to trust the storage medium to hold the data correctly until it's read back. If data got corrupted before it's read back for the first time, I'd have no way to detect that corruption. – UTF-8 Jun 16 '17 at 1:12
1

The problem is that the 7zip file format requires seeking to be available, so you cannot use the 7z file format with -so (per this comment on the project page). Using another format such as xz appears to work:

$ tar -cO Templates | 7z a -an -txz -si -so | tee tarball.xz | sha256sum ; sha256sum tarball.xz

7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,2 CPUs)
Creating archive stdout


Everything is Ok
4349a01e62a7d7b6cfd46caa90ee38904227fc09ef643d87eb8209bc53cb8e50  -
4349a01e62a7d7b6cfd46caa90ee38904227fc09ef643d87eb8209bc53cb8e50  tarball.xz

However, you lose the ability to put a password on the archive this the formats for which this works (gzip, bzip2, and xz).

| improve this answer | |
  • Thanks, this probably helps someone else. But I need the data to be encrypted. I should have mentioned this in the question, not just assumed people notice this from the -p switch being present. Sorry. – UTF-8 Jun 15 '17 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.