我正在通过 nodejs 从 java 应用程序将压缩数据发送到网页。数据使用 java deflater 压缩和 base64 编码。在网页上,我试图用https://github.com/dankogai/js-deflate来膨胀数据,但它不起作用(空结果)。我错过了什么吗?
Java端:
private String compress(String s) {
DeflaterOutputStream def = null;
String compressed = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
// create deflater without header
def = new DeflaterOutputStream(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
def.write(s.getBytes());
def.close();
compressed = Base64.encodeBase64String(out.toByteArray());
System.out.println(compressed);
} catch(Exception e) {
Log.c(TAG, "could not compress data: " + e);
}
return compressed;
}
Javascript方面:
var data = RawDeflate.inflate(Base64.fromBase64(compressed));