ml.bundle.zip.ZipBundleWriter.scala Maven / Gradle / Ivy
The newest version!
package ml.bundle.zip
import java.io.{FileOutputStream, OutputStream, Closeable, File}
import java.util.zip.{ZipEntry, ZipOutputStream}
import ml.bundle.BundleWriter
/**
* Created by hollinwilkins on 3/4/18.
*/
object ZipBundleWriter {
def apply(path: File): ZipBundleWriter = {
ZipBundleWriter(new ZipOutputStream(new FileOutputStream(path)))
}
}
case class ZipBundleWriter(out: ZipOutputStream, path: File = new File("model")) extends BundleWriter {
override def contentWriter(name: String): OutputStream = {
out.putNextEntry(new ZipEntry(new File(path, name).toString))
out
}
override def createBundle(name: String): BundleWriter = {
ZipBundleWriter(out, new File(path, name))
}
override def close(stream: Closeable): Unit = { out.closeEntry() }
}