1
0

Use stream instead of zip file

This commit is contained in:
2020-09-11 17:58:20 +02:00
parent 0d47b51f3f
commit 8a08520267
3 changed files with 19 additions and 28 deletions
+5 -8
View File
@@ -3,22 +3,19 @@ package starter
import starter.templates.Template
import starter.utils.ZipOutput
import starter.utils.sanitizeFilename
import java.io.ByteArrayOutputStream
class ProjectZip(private val templates: List<Template>) {
fun createZip(project: Project): String {
val name: String
fun createZip(project: Project): ByteArrayOutputStream {
val projectName = sanitizeFilename(project.name)
ZipOutput(projectName).use { zip ->
name = zip.name
val zipOutput = ZipOutput()
zipOutput.use { zip ->
templates.filter { it.enabled(project) }.forEach { template ->
zip.write(projectName + "/" + template.path(project), template.render(project))
}
}
return name
return zipOutput.outputStream
}
}