abstract file class fix

This commit is contained in:
chidea 2015-03-22 01:35:00 +09:00
parent cc8d65f76a
commit 75e6c0d17a

View File

@ -1,23 +1,24 @@
from sys import platform
import os
from subprocess import call
# from os import path # path.exists() may used in future.. may be..
from os.path import exists
class File():
def __init__(self, path):
self._path = path
def write_bytes(self, bytes):
''' truncates the file and create new with contents :param bytes '''
with open(self._path, 'r+b') as file:
file.write(bytes)
''' truncates the file and create new with :param bytes.
:return number of bytes written'''
with open(self._path, 'w+b') as file:
return file.write(bytes)
def read_bytes(self):
''' read the file as bytes '''
''' read the file as bytes. :return b'' on file not exist '''
if not exists(self._path): return b''
# buf = b''
with open(self._path, 'r+b') as file:
return file.read() # is this safe?
# buf = file.read()
return file.read()
# return buf
def open(self):