How to use the aiofile.AIOFile function in aiofile

To help you get started, we’ve selected a few aiofile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github YoRyan / sia-slice / tests / View on Github external
async def test_md5_hasher(self):
        async with AIOFile('40MiBempty.img', mode='rb') as afp:
            reference = md5(await
            compare = await ss.md5_hasher(ss.region_read(afp, 0, 40*1000*1000))
        self.assertEqual(compare, reference)
github mosquito / aiofile / tests / View on Github external
def posix_aio_file(name, mode, **kwargs):
        AIOFile.OPERATION_CLASS = posix_aio.AIOOperation
        AIOFile.IO_READ = posix_aio.IO_READ
        AIOFile.IO_NOP = posix_aio.IO_NOP
        AIOFile.IO_WRITE = posix_aio.IO_WRITE

        return AIOFile(name, mode, **kwargs)
github YoRyan / sia-slice / View on Github external
async def amain(args, stdscr=None):
    async with SiadSession(args.api, args.password, debug=args.debug) as session:
        async def siapath():
            if not args.siapath:
                raise ValueError('no siapath specified')
            if not await session.validate_path(args.siapath):
                raise ValueError(f'invalid siapath: {args.siapath}')
            return tuple(args.siapath.split('/'))
        if args.mirror:
            await do_mirror(session, args.file, await siapath(),
                            block_size=args.block*1000*1000, stdscr=stdscr)
            await do_download(session, args.file, await siapath(), stdscr=stdscr)
        elif args.resume:
            async with aiofile.AIOFile(args.file, 'rb') as state_afp:
                state_pickle = pickle.loads(await
            if 'siaslice-mirror' in args.file:
                await do_mirror(
                    session, state_pickle['source_file'], state_pickle['siapath'],
                    block_size=state_pickle['block_size'], stdscr=stdscr)
            elif 'siaslice-download' in args.file:
                await do_download(
                    session, state_pickle['target_file'], state_pickle['siapath'],
                    start_block=state_pickle['start_block'], stdscr=stdscr)
                raise ValueError(f'bad state file: {args.file}')
github checktheroads / hyperglass / hyperglass / render / View on Github external
async def _render_frontend_config():
    """Render user config to JSON for use by frontend."""
    log.debug("Rendering front end config...")

        async with AIOFile(FRONTEND_CONFIG, "w+") as file:
            await file.write(
                        "config": frontend_params,
                        "networks": frontend_networks,
                        "devices": frontend_devices,
            await file.fsync()
        log.debug("Rendered front end config")
    except Exception as e:
        raise HyperglassError(f"Error rendering front end config: {str(e)}")
github YoRyan / sia-slice / View on Github external
async def do_download(session, target_file, siapath, start_block=0, stdscr=None):
    storage = SiapathStorage(session, *siapath)
    await storage.update()

        target_afp = aiofile.AIOFile(target_file, mode='r+b')
    except FileNotFoundError:
        target_afp = aiofile.AIOFile(target_file, mode='wb')

    state_file = f"siaslice-download-{'%Y%m%d-%H%M')}.dat"
    async with aiofile.AIOFile(state_file, mode='wb') as state_afp:
        async for status in siapath_download(storage, target_afp,
            await state_afp.write(pickle.dumps({
                'target_file': target_file,
                'siapath': siapath,
                'current_index': status.current_index}))
            await state_afp.fsync()
            show_status(stdscr, status,
                        title=f'{format_sp(siapath)} -> {target_file}')
github YoRyan / sia-slice / View on Github external
async def do_mirror(session, source_file, siapath, start_block=0,
                    block_size=DEFAULT_BLOCK_MB*1000*1000, stdscr=None):
    storage = SiapathStorage(session, *siapath, default_block_size=block_size)
    await storage.update()

    state_file = f"siaslice-mirror-{'%Y%m%d-%H%M')}.dat"
    async with aiofile.AIOFile(state_file, mode='wb') as state_afp, \
               aiofile.AIOFile(source_file, mode='rb') as source_afp:
        async for status in siapath_mirror(storage, source_afp,
            await state_afp.write(pickle.dumps({
                'source_file': source_file,
                'siapath': siapath,
                'block_size': block_size,
                'current_index': status.current_index}))
            await state_afp.fsync()
            show_status(stdscr, status,
                        title=f'{source_file} -> {format_sp(siapath)}')
github bmoscon / cryptofeed / cryptofeed / util / View on Github external
async def write(self, uuid):
        p = f"{self.path}/{uuid}.{self.count[uuid]}"
        async with AIOFile(p, mode='a') as fp:
            r = await fp.write("\n".join([uuid]) + "\n", offset=self.pointer[uuid])
            self.pointer[uuid] += len(r)
  [uuid] = []

        if self.pointer[uuid] >= self.rotate:
            self.count[uuid] += 1
            self.pointer[uuid] = 0