Last active
December 23, 2019 13:57
-
-
Save samuelorji/76a5918d66cb3d2ddb9f25b5426036fc to your computer and use it in GitHub Desktop.
zip task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy val zip = taskKey[Unit]("zip files") //define the key | |
zip := { // assigning a value to the zip key of type Unit | |
val logger: Logger = sLog.value //get logger from SBT | |
//where to zip from | |
val dirFromZip: File = srcFile.value | |
//where to zip to | |
val dirToZip: File = baseDirectory.value / "build.sbt.zip" | |
logger.info(s"zipping files from ${dirFromZip.absolutePath}") | |
// actual zip function | |
val fos = new FileOutputStream(toZip) | |
val fis = new FileInputStream(dirFromZip) | |
val zipOutputStream = new ZipOutputStream(fos) | |
val zipEntry = new ZipEntry(fromZip.getName) | |
zipOutputStream.putNextEntry(zipEntry) | |
@scala.annotation.tailrec | |
def readAgain(c : Int) : Int = { | |
if(c < 0){ | |
-1 | |
}else{ | |
zipOutputStream.write(c) | |
readAgain(fis.read()) | |
} | |
} | |
readAgain(fis.read()) | |
zipOutputStream.close() | |
fis.close() | |
fos.close() | |
//end of zip function | |
logger.info(s"zipped files to ${dirToZip.absolutePath}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment