Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import os
  2. import sys
  3. import gzip
  4. import shutil
  5.  
  6.  
  7. def gunzip_shutil(source_filepath, dest_filepath, block_size=65536):
  8. '''
  9. TODO: Version with path handling:
  10. dest = source minus suffix
  11. TODO: try/except
  12. TODO: controls (file exists)
  13. TODO: return values
  14. TODO: Documentation
  15.  
  16.  
  17. '''
  18. with gzip.open(source_filepath, 'rb') as s_file, \
  19. open(dest_filepath, 'wb') as d_file:
  20. shutil.copyfileobj(s_file, d_file, block_size)
  21.  
  22.  
  23. file_in = sys.argv[1]
  24.  
  25. filename, file_extension = os.path.splitext(file_in)
  26.  
  27. print(file_in)
  28. print(filename)
  29.  
  30.  
  31. gunzip_shutil(file_in, filename)
  32.  
  33.  
  34.  
  35.  
  36.  
  37. # with gzip.open(file_in, 'rb') as f_in:
  38. # with open(filename, 'wb') as f_out:
  39. # shutil.copyfileobj(f_in, f_out)
  40.  
  41.  
  42.  
  43. # def gzip_shutil(source_filepath, dest_filepath, block_size=65536):
  44. # '''
  45. # TODO: Version with path handling:
  46. # dest = source plus suffix (*.gz)
  47. # TODO: try/except
  48. # TODO: controls (file exists)
  49. # TODO: return values
  50. # TODO: Documentation
  51. # '''
  52.  
  53. # with gzip.open(dest_filepath, 'wb') as f_out:
  54. # with open(source_filepath, 'rb') as f_in:
  55. # shutil.copyfileobj(f_in, f_out)
  56.  
  57.  
  58. # gzip_shutil(filename, file_in)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement