abstract file class fix
This commit is contained in:
parent
cc8d65f76a
commit
75e6c0d17a
@ -1,23 +1,24 @@
|
|||||||
from sys import platform
|
from sys import platform
|
||||||
import os
|
import os
|
||||||
from subprocess import call
|
from subprocess import call
|
||||||
# from os import path # path.exists() may used in future.. may be..
|
from os.path import exists
|
||||||
|
|
||||||
class File():
|
class File():
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self._path = path
|
self._path = path
|
||||||
|
|
||||||
def write_bytes(self, bytes):
|
def write_bytes(self, bytes):
|
||||||
''' truncates the file and create new with contents :param bytes '''
|
''' truncates the file and create new with :param bytes.
|
||||||
with open(self._path, 'r+b') as file:
|
:return number of bytes written'''
|
||||||
file.write(bytes)
|
with open(self._path, 'w+b') as file:
|
||||||
|
return file.write(bytes)
|
||||||
|
|
||||||
def read_bytes(self):
|
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''
|
# buf = b''
|
||||||
with open(self._path, 'r+b') as file:
|
with open(self._path, 'r+b') as file:
|
||||||
return file.read() # is this safe?
|
return file.read()
|
||||||
# buf = file.read()
|
|
||||||
# return buf
|
# return buf
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user