Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labo_blockchain
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
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
denis.gremaud
labo_blockchain
Commits
5847e179
Commit
5847e179
authored
4 years ago
by
Denis Gremaud
Browse files
Options
Downloads
Patches
Plain Diff
labo 1 done
parent
82d55c9d
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
myzip_gremaud_tefridj.py
+64
-0
64 additions, 0 deletions
myzip_gremaud_tefridj.py
test.pdf
+0
-0
0 additions, 0 deletions
test.pdf
test.txt
+1
-0
1 addition, 0 deletions
test.txt
with
65 additions
and
0 deletions
myzip_gremaud_tefridj.py
0 → 100644
+
64
−
0
View file @
5847e179
import
gzip
import
hashlib
import
sys
import
math
import
os
def
read_file
(
file_name
):
file
=
open
(
file_name
,
"
rb
"
)
file_open
=
file
.
read
()
return
file_open
def
write_file
(
file_name
,
data
):
file
=
open
(
file_name
,
"
wb
"
)
file
.
write
(
data
)
file
.
close
()
def
hash
(
file
):
return
hashlib
.
sha1
(
file
).
hexdigest
()
def
compression
(
input_file
):
file
=
read_file
(
input_file
)
hash_input_file
=
hash
(
file
)
print
(
'
hash : {}
'
.
format
(
hash_input_file
))
compressed_value
=
gzip
.
compress
(
bytes
(
file
))
out_file_name
=
os
.
path
.
splitext
(
input_file
)[
0
]
+
'
.gz
'
f
=
gzip
.
open
(
out_file_name
,
'
wb
'
)
f
.
write
(
compressed_value
)
f
.
close
()
def
decompression
(
input_file
,
out_file_name
):
with
gzip
.
open
(
input_file
,
"
rb
"
)
as
f
:
data
=
f
.
read
()
plain_string
=
gzip
.
decompress
(
data
)
write_file
(
out_file_name
,
plain_string
)
test_checksum
(
out_file_name
)
def
test_checksum
(
out_file_name
):
file
=
read_file
(
out_file_name
)
hash_after
=
hash
(
file
)
hash_before
=
str
(
input
(
'
veuillez entrer le hash du fichier avant compression :
'
))
if
hash_after
==
hash_before
:
print
(
'
tout est ok
'
)
else
:
print
(
'
problème lors de la décompression
'
)
def
test_size
(
input_file
):
print
(
"
La taille du fichier est de :
"
)
print
(
"
taille en ko : {}
"
.
format
(
os
.
path
.
getsize
(
input_file
)
/
1000
))
if
len
(
sys
.
argv
)
>
1
:
# on test si on a spécifié un nom de fichier à trier
type_program
=
sys
.
argv
[
1
]
input_file
=
sys
.
argv
[
2
]
if
os
.
path
.
exists
(
input_file
)
==
True
:
if
type_program
==
'
-c
'
:
compression
(
input_file
)
elif
type_program
==
'
-d
'
:
out_file_name
=
sys
.
argv
[
3
]
decompression
(
input_file
,
out_file_name
)
else
:
print
(
'
Paramètre non valide
'
)
else
:
print
(
"
Le fichier spécifié n
'
existe pas !
"
)
# message affiché si le fichier n'existe pas
else
:
print
(
"
Vous devez spécifié un nom de fichier !
"
)
# message affiché si il y a pas de fichier spécifié
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test.pdf
0 → 100644
+
0
−
0
View file @
5847e179
File added
This diff is collapsed.
Click to expand it.
test.txt
0 → 100644
+
1
−
0
View file @
5847e179
test compression
\ No newline at end of file
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