+ shitty download buffering

meow
Dominika 2021-12-16 02:15:59 +01:00
parent 1a38f00be7
commit 5ef61aad02
1 changed files with 14 additions and 7 deletions

21
main.py
View File

@ -13,6 +13,9 @@ assets = {}
headers = {"Authorization":"token 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"}
repo = "owosoftware"
offset_temp = 0 # TODO
buffer_len = 0 # TODO
global buffer;
buffer = b""
def getReleases():
if not releases:
@ -174,16 +177,20 @@ class Passthrough(Operations):
return random.randrange(1,100)
def read(self, path, length, offset, fh):
global buffer
global buffer_len
print("-- read: offset ", offset, " len ", length, " path ", path)
l = length + offset_temp
_h = headers
_h["Range"] = "bytes=" + str(offset_temp) + "-" + str(l-1)
_h["Accept"] = "application/octet-stream"
a = requests.get("https://api.github.com/repos/DomiOwO/" + repo + "/releases/assets/" + str(assets[path.split("/")[-2]][path.split("/")[-1]]["id"]), headers=headers);
if offset + length > buffer_len:
print("buffer exhausted: ", buffer_len)
_h = headers
_h["Range"] = "bytes=" + str(buffer_len) + "-" + str(buffer_len + 10485760) # 5MB
_h["Accept"] = "application/octet-stream"
a = requests.get("https://api.github.com/repos/DomiOwO/" + repo + "/releases/assets/" + str(assets[path.split("/")[-2]][path.split("/")[-1]]["id"]), headers=headers);
buffer += a.content
buffer_len = buffer_len + 10485760
#os.lseek(fh, offset, os.SEEK_SET)
#return os.read(fh, length)
offset_ = offset_temp + offset
return a.content
return buffer[offset:offset+length]
def write(self, path, buf, offset, fh):
print("-- write: offset ", offset, " buf ", buf, " path ", path)