pipe-io-server/pipe_io_server/pipe.py
2018-12-16 21:22:20 +01:00

27 lines
524 B
Python

from os import mkfifo, remove
from os.path import exists
class Pipe:
def __init__(self, path):
self.path = path
def recreate(self):
self.remove()
self.create()
def remove(self):
if exists(self.path):
remove(self.path)
def create(self):
mkfifo(self.path)
def write(self, data):
with open(self.path, 'wb') as pipe:
pipe.write(data)
def read(self):
with open(self.path, 'rb') as pipe:
return pipe.read()