@@ -0,0 +1,1562 @@
+/** -*- tab-width: 4 -*-%0A * This file is part of Erjang - A JVM-based Erlang VM%0A *%0A * Copyright (c) 2010 by Trifork%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A **/%0A%0Apackage erjang.m.zlib;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.util.zip.Deflater;%0Aimport java.util.zip.DeflaterOutputStream;%0A%0Aimport erjang.BIF;%0Aimport erjang.EBinary;%0Aimport erjang.ENative;%0Aimport erjang.EObject;%0Aimport erjang.ERT;%0A%0Apublic class Native extends ENative %7B%0A%0A%09@BIF%0A%09public static EBinary compress(EObject bin) %7B%0A%09%09%0A%09%09EBinary b = bin.testBinary();%0A%09%09if (b == null) %7B%0A%09%09%09throw ERT.badarg(bin);%0A%09%09%7D%0A%09%09%0A%09%09Deflater defl = new Deflater();%0A%09%09BARR bos = new BARR();%0A%09%09DeflaterOutputStream dos = new DeflaterOutputStream(bos, defl);%0A%09%09%0A%09%09try %7B%0A%09%09%09b.writeTo(dos);%0A%09%09%09dos.close();%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09throw new InternalError(%22should not happen%22);%0A%09%09%7D%0A%09%09%0A%09%09return bos.asBinary();%09%09%0A%09%7D%0A%09%0A%09static private class BARR extends ByteArrayOutputStream %7B%0A%09%09EBinary asBinary() %7B%0A%09%09%09return new EBinary(super.buf, 0, super.count);%0A%09%09%7D%0A%09%7D%0A%0A%0A%7D%0A

Implement zlib:compress/1 as a BIF (drawback: compressing large binaries may block)