0
luaの文字列からgzipを解凍するのに問題があります。Luaは文字列からgzipを解凍します
1つのWebサービスの応答は、base64でエンコードされたgzip文字列です。サンプルでは、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);
}
私は(nginxの上の)LUAでこれを行うと、バイト
local byte_table={};
base64.base64_decode(res_string):gsub(".", function(c){
table.insert(byte_table, string.byte(c))
})
のbase64文字列配列から作るが、zlibといくつかの問題を持ってみてください。
IOストリームをluaで使用し、gzipを解凍する方法を理解してください。
? –
どこかでグーグルで調べました。 – FareakyGnome
'ローカル結果= zlib.decompress(base64.base64_decode( 'H4sIAAAAAAAEAHMNCvIPUlRwzS0oqVQoLinKzEtXyC9SyCvNyYFxM/OAqKC0RKEgsSgxN7UktQgAwOaxgjUAAAA =')、31);' ERROR!入力パラメータ –