示例#1
0
    def download(self, ns_path: StrOrPath, path: StrOrPath) -> Iterator[bytes]:
        fullpath = self._joinpath(self.location, ns_path, path)
        pathnames = glob.iglob(self._joinpath(fullpath, "**/*"),
                               recursive=True)
        if os.path.isdir(fullpath):
            paths = [{
                "fs": pathname,
                "n": os.path.relpath(pathname, fullpath),
            } for pathname in pathnames if os.path.isfile(pathname)]
            return zipfly.ZipFly(paths=paths).generator()  # type: ignore

        return self._readchunks(fullpath)
示例#2
0
文件: test.py 项目: zeta1999/zipfly
    def test_buffer_prediction_size(self):

        print("""
            TEST IF REAL ZIP SIZE IS EQUAL TO PREDICTION SIZE
            # # # # # # # # # # # # # # # # # # # # # # # # #
            """)

        for test_n in range(1, 50):

            with self.subTest(i=test_n):

                storesize = 0
                for path in paths1:
                    f = open(path['fs'], 'rb')
                    storesize += os.fstat(f.fileno()).st_size
                    f.close()

                zfly = zipfly.ZipFly(paths=paths1, storesize=storesize)

                zfly.set_comment(rs(pick_n()))

                # zip size before creating it in bytes
                ps = zfly.buffer_prediction_size()

                with open("test{}.zip".format(test_n), "wb") as f:
                    for i in zfly.generator():
                        f.write(i)

                f = open("test{}.zip".format(test_n), 'rb')
                zs = os.fstat(f.fileno()).st_size
                f.close()

                # fetch

                print("test-{}.zip ->".format(test_n),
                      "{} KB".format(round(zs / 1024,
                                           2)), "({} bytes)".format(zs),
                      (" ---- OK" if zs == ps else " ---- FAIL"))

                self.assertEqual(zs, ps)
示例#3
0
paths = [
    {
        'fs': 'home/user/Videos/jupiter.mp4',
        'n': 'movies/jupiter.mp4',
    },
    {
        'fs': 'home/user/Documents/mercury.mp4',
        'n': 'movies/mercury.mp4',
    },
]

storesize = 92896201  # (jupiter.mp4 + mercury.mp4) size in bytes

# constructor
zfly = zipfly.ZipFly(mode='w', paths=paths, storesize=storesize)

# z is a new generator
# (<generator object generator at 0x7f85aad34a50>)
z = zfly.generator()

# flask streaming
response = Response(
    z,
    mimetype='application/zip',
)

# zip size before creating it
content_length = zfly.buffer_prediction_size()

response.headers['Content-Length'] = content_length
import zipfly
import os

paths = [
    {
        'fs': 'home/user/Videos/jupiter.mp4',
        'n': 'movies/jupiter.mp4',
    },
    {
        'fs': 'home/user/Documents/mercury.mp4',
        'n': 'movies/mercury.mp4',
    },
]

storesize = 0
for path in paths:

    # (jupiter.mp4 + mercury.mp4) size in bytes

    f = open(path['fs'], 'rb')
    storesize += os.fstat(f.fileno()).st_size

zfly = zipfly.ZipFly(paths=paths, storesize=storesize)

# zip size before creating it in bytes
print(zfly.buffer_prediction_size())
示例#5
0
import zipfly

paths = [
    {
        'fs': 'home/user/Videos/jupiter.mp4',
        'n': 'movies/jupiter.mp4',
    },
    {
        'fs': 'home/user/Documents/mercury.mp4',
        'n': 'movies/mercury.mp4',
    },
]

zfly = zipfly.ZipFly(paths=paths)

generator = zfly.generator()
print(generator)
# <generator object generator at 0x7f85aad60b13>

with open("test.zip", "wb") as f:
    for i in generator:
        f.write(i)
示例#6
0
 def __zip(self):
     zfly = zipfly.ZipFly(paths=paths)
     generator = zfly.generator()
     with open("test.zip", "wb") as f:
         for i in generator:
             f.write(i)