File tree Expand file tree Collapse file tree 2 files changed +5
-22
lines changed Expand file tree Collapse file tree 2 files changed +5
-22
lines changed Original file line number Diff line number Diff line change 33"""
44
55# built-in
6- import asyncio
76from os import sep
87from pathlib import Path
9- from shutil import which
10- from typing import Iterator , Optional , Union
8+ from typing import Iterator , Union
119
1210# third-party
1311import aiofiles
1412from vcorelib .paths import normalize
1513
1614ROOT_PATH = Path (sep )
17- USE_CAT : Optional [bool ] = None
1815
1916
20- async def read_binary (path : Path , use_aiofiles : bool = False ) -> bytes :
17+ async def read_binary (path : Path ) -> bytes :
2118 """An async wrapper for reading file contents."""
2219
23- global USE_CAT # pylint: disable=global-statement
24- if USE_CAT is None :
25- USE_CAT = which ("cat" ) is not None
26-
27- # Avoid ballooning a thread pool with one-off reads.
28- if USE_CAT and not use_aiofiles :
29- proc = await asyncio .create_subprocess_exec (
30- "cat" , str (path ), stdout = asyncio .subprocess .PIPE
31- )
32- result , _ = await proc .communicate ()
33-
34- else :
35- async with aiofiles .open (path , mode = "rb" ) as path_fd :
36- result = await path_fd .read ()
37-
38- return result
20+ async with aiofiles .open (path , mode = "rb" ) as path_fd :
21+ result = await path_fd .read ()
22+ return result # type: ignore
3923
4024
4125def normalize_root (* src_parts : Union [str , Path ]) -> Path :
Original file line number Diff line number Diff line change @@ -17,4 +17,3 @@ async def test_read_binary():
1717 """Test 'read_binary' invocations."""
1818
1919 assert await read_binary (resource ("test.txt" ))
20- assert await read_binary (resource ("test.txt" ), use_aiofiles = True )
You can’t perform that action at this time.
0 commit comments