• util.Compress returns "]" every single time regardless of input serverside
    9 replies, posted
I'm attempting to compress a JSON table string before networking it over to the client. Originally I was sending the table then compressing it on the client for storage reasons (dumb I know) but eventually I remembered "oh hey yeah networking hates big files and tables get big fast" after a reasonably sized table caused everything to crap out so I swapped the compression to the server side before it gets sent out. Unfortunately this instead returns "]" instead of the compressed string and the weird bit is that even when I send it normal strings like "heylolwhats up dude" it still just returns "]". Do note that this wasn't happening when it was compressing client side and now after I changed it I can't get it to happen on either side. Code in question: concommand.Add("fbg_worldsave", function(ply, cmd, args)     bigTable = {}     local worldObjTable = ents.FindByClass("roblox_brick_*")     --local worldObjDat = {}     --PrintTable(worldObjTable)          bigTable = duplicator.CopyEnts(worldObjTable)          local dupeTable_d = util.TableToJSON(bigTable, true)     print(dupeTable_d)     local dupeTable_c = util.Compress(dupeTable_d)          print("Ugly thing: ")     print(dupeTable_c)          worldSaverThing(ply, dupeTable_c, args[1]) -- DONT RUN THIS IN MP YOUR GONNA BREAK SOME SHIT.     -- Lol in this example I broke that warning ---^     end) Console: https://files.facepunch.com/forum/upload/109874/24a3d5db-66ae-4d41-8978-474bdda42b04/image.png As noted by the client side messages, i'm also printing quick what's shown once it reaches the client in case the net library was just being pissy. Also, due to the table being big I cant show it all. Lastly, any non-local variables you see are initialized locally elsewhere up the code tree outside a function.
just curious, have you tried writing the compressed data to a text file and seeing if it appears in there?
wow would you look at that util.Compress did its job, now we can move on to its buddy util.Decompress which turns that back to the original text! the magic of loseless compression is surely amazing! all hail LZMA!!! ] lua_run_cl a=util.Compress'lolwhat is that'print(a,util.Decompress(a)) ] lolwhat is that
The reason for this is because the return from util.Compress is in a compress binary format, it uses LZMA I think. When you try to print the compressed string, containing weird binary characters after the compression, the console just bails out on the strange characters since it's not real ASCII. If you want to print it and see what's happening for human-readability, try doing a Base64 encode on the compressed data before printing.
Yes, as this function is meant to compress the input data before being sent to the client where it's stored as a text file which is where I first noted that something was up (upon trying to reload the files it wasn't giving me anything). Normally the file comes out as something like this (yes it's supposed to look like verbal sewage): ]   l       =ˆ…¦“®«È¸ž'a×›Ï Õ-•½¨mX(÷v¼ÆÞˆM?s¶ò|Dï±ÅÄ/-ÐF™¿s‚J{%âšeìûÓ­ê¯/i¸Ì€ú7F|ß?4¹£5pÒ¢Œ¤¼N-p§FO:´`GSE¡FEæÚ–ûDpfÈ/¾Q&å½CïI¢3 í+W p¹‚XÝÛŠuíÅôé1WZâï´/ÓOæÂw¾ÐC‚táští%&Põ‚]’È~ž°ÁA›´8ëÑhÕÁguØBA¸/‰¾3õÄÂß'†‰–;êz¨¶W Eÿaƒ{¾}£¥wh •|Q#[ÜpïI¼û Ø–eìz“ešã= .O‚Xq¨žÔäËÔi:L™>ŸÇˆ 3Ë(Ö2Í–t6©¸ËÈ­Rö$ ؆£YÌÝóM¢ÿŠÞ¦Ó^œCJw ®$ y?íPY ¼ãºã¾0B7Šë†x¶'±j½£¼íÌû”aC%“8 f†ü)¼È;vF¸ ¨ãǁ«­ÝÈ⟔“4»‹Ø¹ DÊk!=_Ú™Èx}÷ 0ïUW&­ (NOTE this is a real file from a previous successful attempt) Huh it's almost like you didn't actually read anything in the post because if you did you'd know that it's literally not even compressing it at all and just returning a single character. I mean hell maybe i'm just some retard with a computer information systems degree who doesn't know we've magically figured out how to compress entire blocks of text into a single character. See first response. It's not converting anything at all as far as I can tell as later on in the code it's saved to a text file and now all of a sudden it's just putting the prior mentioned single bracket in.
What is your code to save data to file? What is your code to send the data over .net?
Sure here it is, I didn't originally post it because it tends to get a bit big: Also in the init.lua file (gamemode): function worldSaverThing(ply, worldTable, fileName)     if IsValid(ply) then         net.Start("client_SaveWorld")         net.WriteEntity(ply)         net.WriteTable(worldTable)         net.WriteString(fileName)         net.Send(ply)              end end cl_init.lua side: function magicDupeMachine(dupeTable, fileName)          -- Convert the table to a string (decompressed), Compress it...     local dupeTable_d = util.TableToJSON(dupeTable, false)     local dupeTable_c = util.Compress(dupeTable_d)     PrintTable(dupeTable)     -- Make ourselves a new file name to work with given the filename they want to write to.     local newFileName = "fbg_" .. fileName .. ".txt"          -- Write this to a new file in the /data/ directory!     file.Write(newFileName, dupeTable_C)     if file.Exists(newFileName, "DATA") != true then                  print("OOF! Somethings wrong! Saved file not found!")     else          print("DING! File done saving.")         print("File contents:")         print(file.Read(newFileName, "DATA"))     end end net.Receive("client_SaveWorld", function()     local ply = net.ReadEntity()     local message = net.ReadTable()     local fileName = net.ReadString()     if LocalPlayer() == ply then         magicDupeMachine(message, fileName)     end end)  
So I am assuming you take the raw table from duplicator lib and push it through net library to client, and compress and save the data on client? Have you tried checking if the table you receive on client is there in its entirety?
Ignore that code I posted before. I was dumb and forgot I tried to rewrite it the old way. I'll have the original code in a minute here
You can't use WriteString for binary data that has embedded zeroes. Use WriteData
Sorry, you need to Log In to post a reply to this thread.