This is an implementation of the UStar Tar format as described on Wikipedia.
Archives can be compressed and decompressed using gzip and gunzip methods as well.
NO WARRANTIES, MIT License
Here's an example of how to tar a list of files.
DATA:
it_files TYPE zcl_tar=>ty_files.
DATA:
lv_packed TYPE xstring,
lv_msg TYPE string,
lo_tar_out TYPE REF TO zcl_tar,
lx_error TYPE REF TO zcx_error,
ls_file TYPE zcl_tar=>ty_file.
TRY.
lo_tar_out = zcl_tar=>new( ).
LOOP AT it_files INTO ls_file.
lo_tar_out->append(
iv_name = ls_file-name
iv_content = ls_file-content
iv_date = ls_file-date
iv_time = ls_file-time
iv_mode = ls_file-mode
iv_typeflag = ls_file-typeflag ).
ENDLOOP.
lv_data = lo_tar_out->save( ).
lv_packed = lo_tar_out->gzip( lv_data ).
CATCH zcx_error INTO lx_error.
lv_msg = lx_error->get_text( ).
MESSAGE lv_msg TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
Here's an example of how to untar a file.
DATA:
iv_filename TYPE string,
iv_data TYPE xstring.
DATA:
lv_unpacked TYPE xstring,
lv_filedata TYPE xstring,
lv_msg TYPE string,
lo_tar_in TYPE REF TO zcl_tar,
lx_error TYPE REF TO zcx_error,
ls_file TYPE zcl_tar=>ty_file,
lt_files TYPE zcl_tar=>ty_files.
TRY.
lo_tar_in = zcl_tar=>new( ).
IF iv_filename CP '*.tgz' OR iv_filename CP '*.tar.gz'.
lv_unpacked = lo_tar_in->gunzip( iv_data ).
ELSE.
lv_unpacked = iv_data.
ENDIF.
lo_tar_in->load( lv_unpacked ).
lt_files = lo_tar_in->list( ).
LOOP AT lt_files INTO ls_file.
lv_filedata = lo_tar_in->get( ls_file-name ).
" ...
ENDLOOP.
CATCH zcx_error INTO lx_error.
lv_msg = lx_error->get_text( ).
MESSAGE lv_msg TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
SAP Basis 7.02 or higher
Import ABAP Tar to your project using apm.
IMPORT '*' TO 'z$1_your_project$2' FROM 'tar'.
" or
IMPORT '*' TO '/namespace/$1$2' FROM 'tar'.
All contributions are welcome! Read our Contribution Guidelines, fork this repo, and create a pull request.
You can install the developer version of ABAP Tar using abapGit either by creating a new online repository for https://github.com/abapPM/ABAP-Tar.
Recommended SAP package: $TAR
Made with ❤️ in Canada
Copyright 2024 apm.to Inc. https://apm.to