好吧,我想它仍然沒有實現。該類所做的唯一事情就是在StringIO中返回文件的數據。用純zip文件做這件事更容易。這是我怎麼做的:
# That class is necessary, it's explained why in Loader's class comments
class Cleaner(dict):
pass
class Loader:
def __init__(self):
self.sprite = pyglet.resource.image(self.unzip('test.png'))
self.sprite = pyglet.resource.image(self.unzip('test2.png'))
def unzip(self, file):
zip = zipfile.ZipFile('test.zip')
file = open('.buffer', 'wb')
# without 'b' it wont work on windows
file.write(zip.read(file))
file.close()
'''now the tricky part: pyglet save every file with weakref to
dont load save thing more than once, it wouldnt let to load
files from buffer so we need to block it somehow after each
file reading i do that with empty dict class (dont need to import weakref)'''
pyglet.resource._default_loader._cached_images = Cleaner()
return 'data/.buffer'