|
1 | 1 | # SPDX-FileCopyrightText: 2023 spdx contributors |
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | | -from beartype.typing import Dict, List |
| 4 | +from beartype.typing import Dict, List, IO |
5 | 5 | from rdflib import DOAP, Graph |
6 | 6 | from rdflib.compare import to_isomorphic |
7 | 7 |
|
|
19 | 19 | from spdx_tools.spdx.writer.rdf.snippet_writer import add_snippet_to_graph |
20 | 20 |
|
21 | 21 |
|
22 | | -def write_document_to_file(document: Document, file_name: str, validate: bool, drop_duplicates: bool = True): |
| 22 | +def write_document_to_stream(document: Document, stream: IO[bytes], validate: bool, drop_duplicates: bool = True): |
23 | 23 | if validate: |
24 | 24 | validation_messages: List[ValidationMessage] = validate_full_spdx_document(document) |
25 | 25 | if validation_messages: |
@@ -55,4 +55,9 @@ def write_document_to_file(document: Document, file_name: str, validate: bool, d |
55 | 55 | graph.bind("spdx", SPDX_NAMESPACE) |
56 | 56 | graph.bind("doap", DOAP) |
57 | 57 | graph.bind("ptr", POINTER_NAMESPACE) |
58 | | - graph.serialize(file_name, "pretty-xml", encoding="UTF-8", max_depth=100) |
| 58 | + graph.serialize(stream, "pretty-xml", encoding="UTF-8", max_depth=100) |
| 59 | + |
| 60 | + |
| 61 | +def write_document_to_file(document: Document, file_name: str, validate: bool, drop_duplicates: bool = True): |
| 62 | + with open(file_name, "wb") as out: |
| 63 | + write_document_to_stream(document, out, validate, drop_duplicates) |
0 commit comments