So here's what i found:
Requirements:
https://github.com/jiyinyiyong/json-lua
https://github.com/iskolbin/lbase64
https://github.com/SafeteeWoW/LibDeflate
Example script:
Code: Select all
require 'lib.LibDeflate'
base64 = require("lib.base64")
require 'lib.JSON'
script.on_event(defines.events.on_player_changed_position, function(event)
local example_input = '{"blueprint":{"icons":[{"signal":{"type":"item","name":"assembling-machine-3"},"index":1}],"entities":[{"entity_number":1,"name":"assembling-machine-3","position":{"x":-2,"y":0}},{"entity_number":2,"name":"assembling-machine-3","position":{"x":1,"y":0}}],"item":"blueprint","version":73016934401}}'
local compressed = LibDeflate:CompressZlib(example_input,{strategy="fixed"}) --level = ?? ... can't figure out the exact algorithm the game uses - but fortunately the game doesn't care which compression is used
compressed = base64.encode( compressed)
compressed = "0"..compressed
game.players[1].cursor_stack.import_stack(compressed)
end)
to decode a blueprint-string, simply remove the first character, run base64.decode and then LibDeflate:DecompressZlib
Code: Select all
local test = base64.decode(compressed:sub(2))
test = LibDeflate:DecompressZlib(test)
game.players[1].print(test)