diff --git a/phparchivefile.php b/phparchivefile.php old mode 100644 new mode 100755 diff --git a/pyarchivefile_test.py b/pyarchivefile_test.py deleted file mode 100755 index e212554..0000000 --- a/pyarchivefile_test.py +++ /dev/null @@ -1,55 +0,0 @@ -import unittest -import os -from io import BytesIO -import pyarchivefile # Ensure pyarchivefile.py is accessible - - -class TestPyArchiveFile(unittest.TestCase): - def setUp(self): - """Prepare environment for testing.""" - # Create example files to pack - self.test_files = ['test_file1.txt', 'test_file2.txt'] - for file_name in self.test_files: - with open(file_name, 'w') as f: - f.write(f'Contents of {file_name}\n') - - # Name of the packed file for testing - self.packed_file = 'test_packed.cat' - - def tearDown(self): - """Clean up after tests.""" - # Remove created test files and packed file - for file_name in self.test_files + [self.packed_file]: - try: - os.remove(file_name) - except FileNotFoundError: - pass # File was not created or has been removed already - - def test_pack_files(self): - """Test packing files into a single file.""" - # Assuming a function PackArchiveFile exists for packing files - with open(self.packed_file, 'wb') as out_file: - pyarchivefile.PackArchiveFile( - self.test_files, out_file, compression="none", checksum="none", verbose=False) - - # Check if the packed file has been created - self.assertTrue(os.path.exists(self.packed_file)) - - def test_list_packed_files(self): - """Test listing contents of a packed file.""" - # First, pack files into a single file - with open(self.packed_file, 'wb') as out_file: - pyarchivefile.PackArchiveFile( - self.test_files, out_file, compression="none", checksum="none", verbose=False) - - # Assuming a function ArchiveFileListFiles exists for listing contents - with open(self.packed_file, 'rb') as in_file: - contents = pyarchivefile.ArchiveFileListFiles(in_file, verbose=False) - - # Check if the contents match the packed files - expected_contents = set(self.test_files) - self.assertEqual(set(contents), expected_contents) - - -if __name__ == '__main__': - unittest.main() diff --git a/pyarchivefilealt.py b/pyarchivefilealt.py deleted file mode 100755 index d350a18..0000000 --- a/pyarchivefilealt.py +++ /dev/null @@ -1,73 +0,0 @@ -import os -import sys -import logging -import tarfile -import zlib -import argparse -from io import BytesIO - -# Configure logging -logging.basicConfig(level=logging.INFO) -logger = logging.getLogger(__name__) - - -class ArchiveFilePacker: - def __init__(self, checksum_type='crc32'): - self.checksum_type = checksum_type - - def pack_from_tar(self, tar_path, archivefile_path): - try: - with tarfile.open(tar_path, 'r') as tar, open(archivefile_path, 'wb') as archivefile: - for member in tar.getmembers(): - if member.isfile(): - file_data = tar.extractfile(member).read() - packed_data = self._pack_file_data(file_data, member) - archivefile.write(packed_data) - return True - except tarfile.TarError as e: - logger.error(f"Tar file error: {e}") - return False - except IOError as e: - logger.error(f"I/O error: {e}") - return False - except Exception as e: - logger.error(f"Unexpected error: {e}") - return False - - def _pack_file_data(self, data, member): - metadata = self._create_metadata(member) - checksum = self._calculate_checksum(data) - metadata_length = len(metadata).to_bytes(4, byteorder='little') - data_length = len(data).to_bytes(4, byteorder='little') - packed_data = metadata_length + metadata + data_length + data + checksum - return packed_data - - def _create_metadata(self, member): - name = member.name.encode('utf-8') - size = member.size.to_bytes(8, byteorder='little') - mtime = member.mtime.to_bytes(8, byteorder='little') - mode = member.mode.to_bytes(4, byteorder='little') - metadata = name + size + mtime + mode - return metadata - - def _calculate_checksum(self, data): - if self.checksum_type == 'crc32': - checksum = zlib.crc32(data).to_bytes(4, byteorder='little') - else: - checksum = b'\x00' * 4 # Placeholder for unsupported checksum types - return checksum - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description='Pack files from a TAR archive into a CAT file.') - parser.add_argument('tar_path', help='Path to the TAR file to pack') - parser.add_argument('archivefile_path', help='Path to the CAT file to create') - args = parser.parse_args() - - packer = ArchiveFilePacker(checksum_type='crc32') - success = packer.pack_from_tar(args.tar_path, args.archivefile_path) - if success: - logger.info("Packing completed successfully.") - else: - logger.error("Packing failed.") diff --git a/pyarchivefilealt_test.py b/pyarchivefilealt_test.py deleted file mode 100755 index 3e638b1..0000000 --- a/pyarchivefilealt_test.py +++ /dev/null @@ -1,27 +0,0 @@ -import unittest -# Assuming the script above is named pyarchivefilealt.py -from pyarchivefilealt import ArchiveFilePacker -import os - - -class TestArchiveFilePacker(unittest.TestCase): - def setUp(self): - self.packer = ArchiveFilePacker(checksum_type='crc32') - self.test_tar_path = 'test.tar' - self.test_archivefile_path = 'test.cat' - - def test_pack_from_tar(self): - # Implement this test with actual file operations or mocking - pass - - def test_create_metadata(self): - # Implement this test with actual member data or mocking - pass - - def test_calculate_checksum(self): - # Implement this test with known data and checksums - pass - - -if __name__ == '__main__': - unittest.main()