Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9344343
utils.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
utils.py
View Options
# Copyright (C) 2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
subprocess
class
ZSTFile
:
def
__init__
(
self
,
path
,
mode
=
'r'
):
if
mode
not
in
(
'r'
,
'rb'
,
'w'
,
'wb'
):
raise
ValueError
(
f
"ZSTFile mode {mode} is invalid."
)
self
.
path
=
path
self
.
mode
=
mode
def
__enter__
(
self
):
is_text
=
not
(
self
.
mode
in
(
'rb'
,
'wb'
))
writing
=
self
.
mode
in
(
'w'
,
'wb'
)
if
writing
:
cmd
=
[
'zstd'
,
'-q'
,
'-o'
,
self
.
path
]
else
:
cmd
=
[
'zstdcat'
,
self
.
path
]
self
.
process
=
subprocess
.
Popen
(
cmd
,
text
=
is_text
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
)
return
self
def
__exit__
(
self
,
exc_type
,
exc_value
,
tb
):
self
.
process
.
stdin
.
close
()
self
.
process
.
stdout
.
close
()
self
.
process
.
wait
()
def
read
(
self
,
*
args
):
return
self
.
process
.
stdout
.
read
(
*
args
)
def
write
(
self
,
buf
):
self
.
process
.
stdin
.
write
(
buf
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Fri, Jul 4, 2:20 PM (1 d, 23 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3354316
Attached To
rDDATASET Datasets
Event Timeline
Log In to Comment