Skip to content

Instantly share code, notes, and snippets.

@zaze06
Last active June 11, 2021 15:07
Show Gist options
  • Save zaze06/03c5591e3f5dc16dc8b588f1419d4da0 to your computer and use it in GitHub Desktop.
Save zaze06/03c5591e3f5dc16dc8b588f1419d4da0 to your computer and use it in GitHub Desktop.
update
local FILENAME = '/file.lua'
local cacheBreak = tostring(math.random(0, 99999))
res, err = http.get('https://gist.githubusercontent.com/zaze06/6bcff431e61a7d16d2fa279203a84c8f/raw/52aee7085cd622172e74548785b41aeca63e7986/file.lua?breaker=' .. cacheBreak)
if not res then error(err) end
local code = res.readAll()
if not(fs.exists(FILENAME))
then
local newHarvest = fs.open(FILENAME, 'w')
newHarvest.close()
end
local readFile = fs.open(FILENAME, 'r')
local oldCode = readFile.readAll()
readFile.close()
local file = fs.open(FILENAME, 'w')
if oldCode == code
then
file.write(oldCode)
print('NO CHANGES MADE - Same Code')
else
file.write(code)
print('WRITING UPDATE')
byteDiff = string.len(code) - string.len(oldCode)
if byteDiff >= 0
then
print(tostring(math.abs(byteDiff)) .. ' bytes added')
else
print(tostring(math.abs(byteDiff)) .. ' bytes removed')
end
end
file.close()
res.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment