Ich habe einige Probleme mit dekomprimieren gzip aus String in lua. (mb schlechtes Verständnis)Lua dekomprimieren gzip aus String
Antwort von einem Web-Services ist Base64-codierte Gzip-String, für Beispiel bekomme ich etwas Code auf C#.
public static string Decompress(byte[] value, Encoding Encoding = null)
{
if (value == null) return null;
Encoding = Encoding ?? System.Text.Encoding.Unicode;
using (var inputStream = new MemoryStream(value))
using (var outputStream = new MemoryStream())
{
using (var zip = new GZipStream(inputStream, CompressionMode.Decompress))
{
byte[] bytes = new byte[4096];
int n;
while ((n = zip.Read(bytes, 0, bytes.Length)) != 0)
{
outputStream.Write(bytes, 0, n);
}
zip.Close();
}
return Encoding.GetString(outputStream.ToArray());
}
}
static void Main(string[] args)
{
const string encodedText = "H4sIAAAAAAAEAHMNCvIPUlRwzS0oqVQoLinKzEtXyC9SyCvNyYFxM/OAqKC0RKEgsSgxN7UktQgAwOaxgjUAAAA=";
byte[] decodedBytes = Convert.FromBase64String(encodedText);
var decodedString = Decompress(decodedBytes, Encoding.UTF8);
Console.WriteLine(decodedString);
}
Ich versuche, dies mit lua zu tun (auf nginx) und machen aus base64 String-Array von Byte
local byte_table={};
base64.base64_decode(res_string):gsub(".", function(c){
table.insert(byte_table, string.byte(c))
})
aber ein Problem mit zlib haben.
Bitte helfen Sie mir zu verstehen, wie kann ich IO-Stream in Lua verwenden und Gzip dekomprimieren.
Wo u diese magische Zahl 31 erhalten? –
Ich habe es irgendwo gegoogelt. – FareakyGnome
'lokales Ergebnis = zlib.decompress (base64.base64_decode ('H4sIAAAAAAAEAHMNCvIPUlRwzS0oqVQoLinKzEtXyC9SyCvNyYFxM/OAqKC0RKEgsSgxN7UktQgAwOaxgjUAAAA ='), 31);' ERROR! Leerer String oder Null-String im Eingangsparameter –