Advertisement
DeaD_EyE

cpio do not use it

Feb 17th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. def create_cpio(files, name):
  2.     pipe = subprocess.PIPE
  3.     all_pipe = {'stdin': pipe, 'stdout': pipe, 'stderr': pipe}
  4.     proc = subprocess.Popen(['cpio', '-o'], **all_pipe)
  5.     for file in files:
  6.         proc.stdin.write(file.encode())
  7.         proc.stdin.write(b'\n')
  8.     proc.stdin.close()
  9.     with gzip.open(name + '.cpio.gz', 'wb') as fd:
  10.         for chunk in iter(lambda: proc.stdout.read(512*1024**1), b''):
  11.             fd.write(chunk)
  12.     proc.wait()
  13.  
  14. def extract_cpio(file):
  15.     if file.endswith('.cpio'):
  16.         open_func = open
  17.     elif file.endswith('.cpio.gz'):
  18.         open_func = gzip.open
  19.     with open_func(file, 'rb') as fd:
  20.         proc = subprocess.Popen(['cpio', '-i'], stdin=subprocess.PIPE, stderr=subprocess.PIPE)
  21.         for chunk in iter(lambda: fd.read(512*1024**1), b''):
  22.             proc.stdin.write(chunk)
  23.         proc.stdin.close()
  24.     ret = proc.wait()
  25.     return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement