Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create_cpio(files, name):
- pipe = subprocess.PIPE
- all_pipe = {'stdin': pipe, 'stdout': pipe, 'stderr': pipe}
- proc = subprocess.Popen(['cpio', '-o'], **all_pipe)
- for file in files:
- proc.stdin.write(file.encode())
- proc.stdin.write(b'\n')
- proc.stdin.close()
- with gzip.open(name + '.cpio.gz', 'wb') as fd:
- for chunk in iter(lambda: proc.stdout.read(512*1024**1), b''):
- fd.write(chunk)
- proc.wait()
- def extract_cpio(file):
- if file.endswith('.cpio'):
- open_func = open
- elif file.endswith('.cpio.gz'):
- open_func = gzip.open
- with open_func(file, 'rb') as fd:
- proc = subprocess.Popen(['cpio', '-i'], stdin=subprocess.PIPE, stderr=subprocess.PIPE)
- for chunk in iter(lambda: fd.read(512*1024**1), b''):
- proc.stdin.write(chunk)
- proc.stdin.close()
- ret = proc.wait()
- return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement