Added ZLIB!

This commit is contained in:
Victorious Children Studios 2023-12-19 21:50:31 +02:00
parent 743d7ae95a
commit 1927feb37a
2 changed files with 28 additions and 4 deletions

View file

@ -3,6 +3,7 @@
import os import os
import json import json
import zlib
import time import time
import fnmatch import fnmatch
import threading import threading
@ -85,22 +86,26 @@ def down(win, website, filename, fsize=100000):
# downloading the file # downloading the file
url = website+"/download"+filename url = website+"/download_z"+filename
response = urllib.request.urlopen(url) response = urllib.request.urlopen(url)
savef = open(win.project+filename, "wb") savef = open(win.project+filename, "wb")
zd = b""
sofar = 0 sofar = 0
chunk = response.read(8192) chunk = response.read(8192)
while chunk: while chunk:
savef.write(chunk) zd = zd + chunk
chunk = response.read(8192) chunk = response.read(8192)
sofar = sofar + 8192 sofar = sofar + 8192
win.current["http-server"]["message"] = filename[filename.rfind("/")+1:] win.current["http-server"]["message"] = filename[filename.rfind("/")+1:]
win.current["http-server"]["fileprog"] = sofar / fsize win.current["http-server"]["fileprog"] = sofar / fsize
unz = zlib.decompress(zd)
savef.write(unz)
savef.close() savef.close()
def download_missing_changed(win, cur): def download_missing_changed(win, cur):

View file

@ -9,6 +9,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
from subprocess import * from subprocess import *
import json import json
import os import os
import zlib
import sys import sys
import time import time
import random import random
@ -221,7 +222,25 @@ class handler(BaseHTTPRequestHandler):
self.start_page(404) self.start_page(404)
self.wfile.write(b"File: "+filename.encode("utf-8")+b" doen't exist") self.wfile.write(b"File: "+filename.encode("utf-8")+b" doen't exist")
elif self.path.startswith("/download_z/"):
filename = self.path[9:]
fullfilename = PROJECT+filename
if os.path.exists(fullfilename):
self.start_page(200)
self.send_header('Content-type', mimetypes.guess_type(filename))
self.end_headers()
f = open(fullfilename, "rb")
f = f.read()
z = zlib.compress(f)
self.wfile.write(z)
else:
self.start_page(404)
self.wfile.write(b"File: "+filename.encode("utf-8")+b" doen't exist")
try: try:
PORT = int(sys.argv[1]) PORT = int(sys.argv[1])