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

View file

@ -9,6 +9,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
from subprocess import *
import json
import os
import zlib
import sys
import time
import random
@ -221,6 +222,24 @@ class handler(BaseHTTPRequestHandler):
self.start_page(404)
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: