File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -29,18 +29,23 @@ def get_tmp_mount_point(tmp_root: Path = Path(tempfile.gettempdir())) -> Path:
29
29
return Path (tempfile .mkdtemp (prefix = "mnt_" , dir = tmp_root ))
30
30
31
31
32
- def get_tmp_file (tmp_root : Path = Path (tempfile .gettempdir ())) -> Path :
32
+ def get_tmp_file (
33
+ tmp_root : Path = Path (tempfile .gettempdir ()), size : int = 0
34
+ ) -> Path :
33
35
"""
34
36
Return a temporary file within the temporary directory
35
37
36
38
Parameters:
37
39
tmp_root: Directory in which to create temporary file.
40
+ size: If provided, create a file of size bytes
38
41
39
42
Returns:
40
43
tmp_file: Location of temporary file.
41
44
"""
42
- (fd , file_name ) = tempfile .mkstemp (dir = tmp_root )
43
- os .close (fd )
45
+ fd , file_name = tempfile .mkstemp (dir = tmp_root )
46
+ if size != 0 :
47
+ with os .fdopen (fd , "wb" ) as f :
48
+ f .write (os .urandom (size ))
44
49
return Path (file_name )
45
50
46
51
You can’t perform that action at this time.
0 commit comments