SHARE
TWEET

cpio do not use it

DeaD_EyE Feb 17th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top