我压缩采用pako.js
js压缩代码: function compressStr() {
var sstr = '我是未压缩的字符串';
sstr = decodeURIComponent(encodeURIComponent(sstr));
var cpredString = pako.deflate(sstr,{to:'string'});
return cpredString;
}
我的java解压缩代码
public static byte[] decompressStrToBytes(String instr) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(instr.getBytes("utf-8"));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
InflaterInputStream iis = new InflaterInputStream(bis, new Inflater(true));
int readCount = 0;
byte[] buf = new byte[1024];
try {
while ((readCount = iis.read(buf, 0, buf.length)) > 0) {
bos.write(buf, 0, readCount);
}
iis.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
return bos.toByteArray();
}
前端数据可以正确交给服务端,服务端无法正确解压,错误:invalid stored block lengths
请教各位大神。