コード例 #1
0
ファイル: acd_cli.py プロジェクト: Timdawson264/acd_cli
def cat_action(args: argparse.Namespace) -> int:
    if not query.get_node(args.node):
        return INVALID_ARG_RETVAL

    try:
        content.chunked_download(args.node, sys.stdout.buffer)
    except RequestError as e:
        logger.error('Downloading failed. Code: %s, msg: %s' % (e.status_code, e.msg))
        return UL_DL_FAILED

    return 0
コード例 #2
0
ファイル: test_api_live.py プロジェクト: StSimmons/acd_cli
 def test_download_chunked(self):
     ch_sz = gen_rand_sz()
     content.CHUNK_SIZE = ch_sz
     fn, sz = gen_rand_file(size=5 * ch_sz)
     md5 = hashing.hash_file(fn)
     n = content.upload_file(fn)
     self.assertEqual(n['contentProperties']['md5'], md5)
     os.remove(fn)
     self.assertFalse(os.path.exists(fn))
     f = io.BytesIO()
     content.chunked_download(n['id'], f, length=sz)
     trash.move_to_trash(n['id'])
     dl_md5 = hashing.hash_bytes(f)
     self.assertEqual(sz, f.tell())
     self.assertEqual(md5, dl_md5)
コード例 #3
0
ファイル: test_api_live.py プロジェクト: Timdawson264/acd_cli
 def test_download_chunked(self):
     ch_sz = gen_rand_sz()
     content.CHUNK_SIZE = ch_sz
     fn, sz = gen_rand_file(size=5 * ch_sz)
     md5 = hashing.hash_file(fn)
     n = content.upload_file(fn)
     self.assertEqual(n['contentProperties']['md5'], md5)
     os.remove(fn)
     self.assertFalse(os.path.exists(fn))
     f = io.BytesIO()
     content.chunked_download(n['id'], f, length=sz)
     trash.move_to_trash(n['id'])
     dl_md5 = hashing.hash_bytes(f)
     self.assertEqual(sz, f.tell())
     self.assertEqual(md5, dl_md5)
コード例 #4
0
ファイル: test_api_live.py プロジェクト: StSimmons/acd_cli
 def test_download_resume(self):
     ch_sz = gen_rand_sz()
     content.CHUNK_SIZE = ch_sz
     content.CONSECUTIVE_DL_LIMIT = ch_sz
     fn, sz = gen_rand_file(size=5 * ch_sz)
     md5 = hashing.hash_file(fn)
     n = content.upload_file(fn)
     self.assertEqual(n['contentProperties']['md5'], md5)
     os.remove(fn)
     self.assertFalse(os.path.exists(fn))
     p_fn = fn + content.PARTIAL_SUFFIX
     with open(p_fn, 'wb') as f:
         content.chunked_download(n['id'], f, length=int(sz * random.random()))
     self.assertLess(os.path.getsize(p_fn), sz)
     content.download_file(n['id'], fn)
     trash.move_to_trash(n['id'])
     dl_md5 = hashing.hash_file(fn)
     self.assertEqual(md5, dl_md5)
     os.remove(fn)
コード例 #5
0
ファイル: test_api_live.py プロジェクト: Timdawson264/acd_cli
 def test_download_resume(self):
     ch_sz = gen_rand_sz()
     content.CHUNK_SIZE = ch_sz
     content.CONSECUTIVE_DL_LIMIT = ch_sz
     fn, sz = gen_rand_file(size=5 * ch_sz)
     md5 = hashing.hash_file(fn)
     n = content.upload_file(fn)
     self.assertEqual(n['contentProperties']['md5'], md5)
     os.remove(fn)
     self.assertFalse(os.path.exists(fn))
     p_fn = fn + content.PARTIAL_SUFFIX
     with open(p_fn, 'wb') as f:
         content.chunked_download(n['id'],
                                  f,
                                  length=int(sz * random.random()))
     self.assertLess(os.path.getsize(p_fn), sz)
     content.download_file(n['id'], fn)
     trash.move_to_trash(n['id'])
     dl_md5 = hashing.hash_file(fn)
     self.assertEqual(md5, dl_md5)
     os.remove(fn)