系统设计题,注意拆分content
'''
Definition of BaseGFSClient
class BaseGFSClient:
def readChunk(self, filename, chunkIndex):
# Read a chunk from GFS
def writeChunk(self, filename, chunkIndex, content):
# Write a chunk to GFS
'''
class GFSClient(BaseGFSClient):
"""
@param: chunkSize: An integer
"""
def __init__(self, chunkSize):
# do intialization if necessary
self.size = chunkSize
self.dic = collections.defaultdict(list)
"""
@param: filename: a file name
@return: conetent of the file given from GFS
"""
def read(self, filename):
# write your code here
if filename not in self.dic:return
temp = ''
print(self.dic[filename])
for i in range(len(self.dic[filename])):
temp += self.dic[filename][i]
return temp
"""
@param: filename: a file name
@param: content: a string
@return: nothing
"""
def write(self, filename, content):
# write your code here
if filename in self.dic:
self.dic[filename] = []
i = 0
while i < len(content):
self.dic[filename].append(content[i:i+self.size])
i = min(i+self.size, len(content))
#print(len(content))
#print(i)