Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompressing file doesn't create a directory #2469

Closed
jin8495 opened this issue Jan 13, 2021 · 3 comments
Closed

Decompressing file doesn't create a directory #2469

jin8495 opened this issue Jan 13, 2021 · 3 comments

Comments

@jin8495
Copy link

jin8495 commented Jan 13, 2021

Describe the bug
First, I compressed a directory which has many files. And then I decompressed it. But the decompressed one is not a directory. It was a file. So, I cannot get in to the directory to search a specific file that I want.

To Reproduce

  1. $ zstd -r --ultra DIRECTORY -o DIRECTORY.zst
  2. $ zstd -d DIRECTORY.zst
  3. decompressed one is not a directory!

Expected behavior
I just wanted to get my file. but '$ cd DIRECTORY' doesn't work.

Desktop (please complete the following information):

  • OS: ubuntu 18.04
  • Version: zstd CLI 64-bits v1.4.5
@Cyan4973
Copy link
Contributor

Cyan4973 commented Jan 13, 2021

-o FILE.zst achieves exactly the same thing as -c > FILE.zst.

The second formulation is maybe clearer in what it does: it merely pushes all compressed frames into FILE.zst, directly appending them to each other, with no additional metadata (only the content).
That means, it has no knowledge of what a directory is, and it doesn't even know what filenames are. This pack of concatenated frames cannot, on its own, regenerate the original directory.

Recent versions of zstd warn against such misunderstanding, by issuing a warning message when they detect this pattern, or even requiring the use of -f force mode to bypass protection.

zstd: WARNING: all input files will be processed and concatenated into a single output file: dir.zst
The concatenated output CANNOT regenerate the original directory tree.

In order to achieve your goal (saving and compacting a complete directory), it's necessary to use a proper archiver like tar. Then pipe the result to zstd. The reverse operation (zstd -d | tar x) will regenerate the directory fully (including all metadata, such as creation / modification time, read /write access, etc.). And it will also compress better.

See #1526 for additional details (this question is effectively a duplicate).

@jin8495
Copy link
Author

jin8495 commented Jan 15, 2021

Thank you for the reply. I have already compressed my files which are stored in the directory. I think I have to throw away them ;(

@jin8495 jin8495 closed this as completed Jan 15, 2021
@terrelln
Copy link
Contributor

@jin8495 you can use the tool I'm adding in PR #2473 to recover your files. You won't get any of the file names or metadata back, but it will split all the file content up correctly. Once it is merged you can run:

git clone https://github.com/facebook/zstd
cd zstd/contrib/recovery
make recover_directory
mkdir recovered/
./recover_directory DIRECTORY.zst recovered/

It will write each file to recovered/N in the order they were compressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants