Skip to content

Commit

Permalink
Add gzip support to --file
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmoore committed Dec 11, 2024
1 parent 4ad1350 commit d234329
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/omero_rdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


import contextlib
import gzip
import sys
import json
import logging
Expand All @@ -46,11 +47,15 @@
Examples:
omero rdf Image:123 # Streams each triple found in N-Triples format
omero rdf -F=jsonld Image:123 # Collects all triples and prints formatted output
omero rdf -S=flat Project:123 # Do not recurse into containers ("flat-strategy")
omero rdf --trim-whitespace ... # Strip leading and trailing whitespace from text
omero rdf --first-handler-wins ... # First mapping wins; others will be ignored
omero rdf --file - ... # Write RDF triples to stdout
omero rdf --file output.nt ... # Write RDF triples to the specified file
omero rdf --file output.nt.gz # Write RDF triples to the specified file, gzipping
"""

Expand All @@ -77,7 +82,10 @@ def open_with_default(filename=None, filehandle=sys.stdout):
if filename == "-":
fh = sys.stdout
else:
fh = open(filename, "w")
if filename.endswith(".gz"):
fh = gzip.open(filename, "wt")
else:
fh = open(filename, "w")
close = True
else:
fh = filehandle
Expand Down

0 comments on commit d234329

Please sign in to comment.