ComputerCraft Archive

bulkget

computer utility kepler155c github

Description

ComputerCraft OS

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/kepler155c/opus/develop-1.8/sys/modules/opus/bulkget.lua bulkget
Archive:wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-modules-opus-bulkget bulkget
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-modules-opus-bulkget bulkget

Usage

Run: bulkget

Tags

none

Source

View Original Source

Code Preview

local Util = require('opus.util')

local parallel = _G.parallel

local BulkGet = { }

function BulkGet.download(list, callback)
	local t = { }
	local failed = false

	for _ = 1, 5 do
		table.insert(t, function()
			while true do
				local entry = table.remove(list)
				if not entry then
					break
				end
				local s, m = Util.download(entry.url, entry.path)
				if not s then
					failed = true
				end
				callback(entry, s, m)
				if failed then
					break
				end
			end
		end)
	end

	parallel.waitForAll(table.unpack(t))
end

return BulkGet