Hy Guys,所以在您帮助我正确转换“压缩”功能后,我也尝试转换解压缩功能
现在我在这里(我的解压功能)
let DecompressString (detext : string) =
let buffer = Convert.FromBase64String detext
using (new MemoryStream ()) <| fun memoryStream ->
using (new GZipStream(memoryStream, CompressionMode.Decompress, true)) <| fun gzipStream ->
memoryStream.Position <- 0L
memoryStream.Read(buffer, 0, Array.length buffer)
Encoding.UTF8.GetString(buffer)
原来的压缩函数是
let compressString (text : string) =
let buffer = Encoding.UTF8.GetBytes text
using (new MemoryStream ()) <| fun memoryStream ->
using (new GZipStream(memoryStream, CompressionMode.Compress, true)) <| fun gzipStream ->
gzipStream.Write (buffer, 0, Array.length buffer)
memoryStream.Position <- 0L
let compressedData = Array.zeroCreate (int memoryStream.Length)
memoryStream.Read (compressedData, 0, compressedData.Length)
let gzipBuffer = Array.zeroCreate (compressedData.Length + 4)
Buffer.BlockCopy (compressedData, 0, gzipBuffer, 4, compressedData.Length)
Buffer.BlockCopy (BitConverter.GetBytes buffer.Length, 0, gzipBuffer, 0, 4)
Convert.ToBase64String gzipBuffer
如果我压缩这样的字符串
File.WriteAllText("test",compressString("bla"))
(我在这个文件中保存的名为“test”的文件是来自“bla”的压缩字符串)
” AwAAAB+LCAAAAAAABADtvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee++997o7nU4n99//P1xmZAFs9s5K2smeIYCqyB8/fnwfPyImZfb/ADmz70cDAAAA
“<对我来说似乎比以前更大?:D
好的,现在我尝试再次解压缩它,例如:
File.WriteAllText("test2",DecompressString(File.ReadAllText("test")))
但在新的“test2”文件中只有不可读的文本,如:
" ?"&e�ï¿
"
所以我认为我的 dcompress 功能不能正常工作。
也许你的英雄可以帮助我第二次也是最后一次?:) 无论如何提前谢谢