-
Notifications
You must be signed in to change notification settings - Fork 0
/
FSNode_File.py
33 lines (28 loc) · 1.05 KB
/
FSNode_File.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from FSNode import FSNode
class FSNode_File(FSNode):
"""
A file in the file system. Just contains text data
"""
def __init__(self, name, parent):
FSNode.__init__(self, name, parent)
self.data = ""
def get_type(self):
return "FSNODE_FILE"
def write(self, offset, data):
"""
Writes data to the buffer starting at the desired offset. The buffer
will be extended to the needed size.
"""
# Check if the data buffer needs to grow
if offset + len(data) > len(self.data):
# Grow with spaces
self.data = self.data + " " * (offset + len(data) - len(self.data))
# Overwrite the desired area
self.data = self.data[:offset] + data + self.data[offset+len(data):]
def read(self, offset, length):
"""
Reads data from the buffer starting at the desired offset up to the
desired length. If the offset is larger than the file, then an empty
string is returned
"""
return self.data[offset:offset+length]