OasisPlatform icon indicating copy to clipboard operation
OasisPlatform copied to clipboard

Add mechanism to list, and return individual files from tar

Open sambles opened this issue 3 years ago • 1 comments

Issue Description

Feature

  • Add option to return a list files stored in the tar file
  • Add option to return single (or optional a selection) of files stored inside the tar blob

Should apply to two endpoints.

  • /v1/analyses/{id}/input_file/ - Stores the oasis-files data from generating oasis files from exposure
  • /v1/analyses/{id}/output_file/ - Stores the output reports from a complete loss analysis

sambles avatar Sep 06 '22 11:09 sambles

Unix tar utility allows extracting specific files from an archive without extracting the whole archive. I've done a quick test:

create a tar with some files in it, then extract just one file

mtazzari@oasisMT:~$ tree test_tar/
test_tar/
├── file1
├── file2
├── file3
├── subdir1
│   ├── file1
│   └── file2
└── subdir2
    └── file1

2 directories, 6 files

# create a tar gz of test_tar/ directory
mtazzari@oasisMT:~$ tar -zcvf test_tar.tar.gz test_tar

# list the content of the tar gz
mtazzari@oasisMT:~$ tar -tvf test_tar.tar.gz
drwxrwxr-x mtazzari/mtazzari 0 2022-12-19 15:41 test_tar/
drwxrwxr-x mtazzari/mtazzari 0 2022-12-19 15:42 test_tar/subdir1/
-rw-rw-r-- mtazzari/mtazzari 0 2022-12-19 15:42 test_tar/subdir1/file2
-rw-rw-r-- mtazzari/mtazzari 0 2022-12-19 15:41 test_tar/subdir1/file1
drwxrwxr-x mtazzari/mtazzari 0 2022-12-19 15:42 test_tar/subdir2/
-rw-rw-r-- mtazzari/mtazzari 0 2022-12-19 15:42 test_tar/subdir2/file1
-rw-rw-r-- mtazzari/mtazzari 0 2022-12-19 15:41 test_tar/file2
-rw-rw-r-- mtazzari/mtazzari 0 2022-12-19 15:41 test_tar/file3
-rw-rw-r-- mtazzari/mtazzari 0 2022-12-19 15:41 test_tar/file1

# rename the original test_tar directory to avoid clashes
mtazzari@oasisMT:~$ mv test_tar test_tar_orig

# extract just file1 from subdir1 from the tar gz
mtazzari@oasisMT:~$ tar -xvf test_tar.tar.gz test_tar/subdir1/file1
test_tar/subdir1/file1

# confirm: just the wanted file was extracted
mtazzari@oasisMT:~$ tree test_tar
test_tar
└── subdir1
    └── file1

1 directory, 1 file
mtazzari@oasisMT:~$ 

mtazzari avatar Dec 19 '22 15:12 mtazzari