好吧,我想它仍然没有实现。该类唯一要做的就是在 StringIO 中返回文件的数据。使用纯 zipfile 做到这一点更加容易。我就是这样做的:
# 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'