Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soitool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bachelor-paa-bittet
soitool
Commits
e695de57
Commit
e695de57
authored
5 years ago
by
morkolai
Browse files
Options
Downloads
Patches
Plain Diff
#69 Fikset docstring og parameternavn
parent
3d85c8de
No related branches found
No related tags found
1 merge request
!38
#69 Komprimering og dekomprimering
Pipeline
#75782
passed
5 years ago
Stage: lint
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
soitool/compressor.py
+34
-18
34 additions, 18 deletions
soitool/compressor.py
with
34 additions
and
18 deletions
soitool/compressor.py
+
34
−
18
View file @
e695de57
...
...
@@ -5,46 +5,62 @@ import json
import
codecs
def
compress
(
soi
):
def
compress
(
obj
):
"""
Compress a soi using the lzma algorithm.
Compress a json compatible object using the lzma algorithm.
JSON compapitle object are python types that are posible to convert to
JSON types. Se overview in this link:
https://docs.python.org/3/library/json.html#py-to-json-table
Parameters
----------
soi : di
ct
soi as di
ct to
be
compres
esed
obj : json compatible obje
ct
Obje
ct to compres
s
Returns
-------
string
The compressed
soi as a
string
The compressed
data casted from bytest to
string
"""
soi
=
json
.
dumps
(
soi
)
soi
=
soi
.
encode
(
encoding
=
"
ascii
"
)
return
str
(
lzma
.
compress
(
soi
))
obj
=
json
.
dumps
(
obj
)
obj
=
obj
.
encode
(
encoding
=
"
ascii
"
)
return
str
(
lzma
.
compress
(
obj
))
def
decompress
(
file
):
def
decompress
(
lzma_compressed_json_string
):
"""
Decompress to python dict.
Decompress a lzma compressed json string.
Decompresses a json compatible python object which is casted from bytes to
string.
Parameters
----------
file
: string
lzma_compressed_json_string
: string
The string of the compressed object
Returns
-------
dict
The decompressed file as dict
python object
One of these python objects:
https://docs.python.org/3/library/json.html#py-to-json-table
"""
# Removes extra b' notation
file
=
file
[
2
:
-
1
].
encode
(
encoding
=
"
ascii
"
)
lzma_compressed_json_string
=
lzma_compressed_json_string
[
2
:
-
1
].
encode
(
encoding
=
"
ascii
"
)
# Remove double \\
file
=
codecs
.
escape_decode
(
file
,
"
hex
"
)
lzma_compressed_json_string
=
codecs
.
escape_decode
(
lzma_compressed_json_string
,
"
hex
"
)
# Decompress
file
=
lzma
.
decompress
(
file
[
0
])
lzma_compressed_json_string
=
lzma
.
decompress
(
lzma_compressed_json_string
[
0
]
)
# Cast to ascii string
file
=
file
.
decode
(
encoding
=
"
ascii
"
)
lzma_compressed_json_string
=
lzma_compressed_json_string
.
decode
(
encoding
=
"
ascii
"
)
# Return as python datastructure
return
json
.
loads
(
file
)
return
json
.
loads
(
lzma_compressed_json_string
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment