Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
revert the linked list can add implementation later
Browse files Browse the repository at this point in the history
  • Loading branch information
birdup000 committed Apr 22, 2023
1 parent aa07ff6 commit 82e1870
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
3 changes: 1 addition & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"world_countries_lists": "^2.5.1",
"concat-stream": "^2.0.0",
"axios-parallel": "^1.1.2",
"fastpriorityqueue": "0.7.4",
"linked-list-typescript": "^1.0.15"
"fastpriorityqueue": "0.7.4"
},
"scripts": {
"start": "react-scripts --openssl-legacy-provider --no-experimental-fetch start",
Expand Down
31 changes: 5 additions & 26 deletions web/src/utils/Download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { Api } from 'telegram'
import { telegramClient } from './Telegram'
import { concat } from 'concat-stream'
import FastPriorityQueue from 'fastpriorityqueue'
import { LinkedList, LinkedListNode } from 'linked-list-typescript'
// Access LinkedListNode class
const node = new LinkedListNode(1)
class ConnectionPool {
private connections: Promise<any>[]
public maxSize: number
Expand Down Expand Up @@ -55,7 +52,7 @@ async function* generateChunks(
let offset = Math.floor(i / numConnections) * media.size / numParallel
const limit = media.size / numParallel
const promises: Promise<Uint8Array[]>[] = []
let buffer = new LinkedList<Uint8Array>()
let buffer: Uint8Array[] = []
let bufferLength = 0
for (let j = 0; j < numParallel; j++) {
const client = clients[connIndex]
Expand All @@ -70,12 +67,12 @@ async function* generateChunks(
if (result.status === 'fulfilled') {
const chunks = result.value
for (const chunk of chunks) {
buffer.append(chunk)
buffer.push(chunk)
bufferLength += chunk.byteLength
if (bufferLength >= bufferSize) {
const concatenated = concatenateLinkedList(buffer)
const concatenated = concat(buffer)
yield concatenated
buffer = new LinkedList<Uint8Array>()
buffer = []
bufferLength = 0
}
}
Expand All @@ -84,28 +81,10 @@ async function* generateChunks(
}
}
if (bufferLength > 0) {
const concatenated = concatenateLinkedList(buffer)
const concatenated = concat(buffer)
yield concatenated
}
}

function concatenateLinkedList(list: LinkedList<Uint8Array>): Uint8Array {
let length = 0
for (
let node: LinkedListNode<Uint8Array> | null = list.head;
node;
node = node.next
) {
length += node.data.byteLength
}
const result = new Uint8Array(length)
let offset = 0
for (let node = list.head; node; node = node.next) {
result.set(node.data, offset)
offset += node.data.byteLength
}
return result
}
export async function download(
id: string,
numParallel: number = 1
Expand Down

0 comments on commit 82e1870

Please sign in to comment.