• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ndkports
18 
19 import java.io.File
20 import java.io.FileInputStream
21 import java.io.FileOutputStream
22 import java.util.zip.ZipEntry
23 import java.util.zip.ZipOutputStream
24 
25 private fun zipDirectory(name: String, zipOut: ZipOutputStream) {
26     zipOut.putNextEntry(ZipEntry("$name/"))
27     zipOut.closeEntry()
28 }
29 
zipFilenull30 private fun zipFile(file: File, name: String, zipOut: ZipOutputStream) {
31     zipOut.putNextEntry(ZipEntry(name))
32     FileInputStream(file).use {
33         it.copyTo(zipOut)
34     }
35 }
36 
zipnull37 private fun zip(file: File, name: String, zipOut: ZipOutputStream) {
38     if (file.isDirectory) {
39         zipDirectory(name, zipOut)
40     } else {
41         zipFile(file, name, zipOut)
42     }
43 }
44 
createZipFromDirectorynull45 fun createZipFromDirectory(output: File, input: File) {
46     FileOutputStream(output).use { fos ->
47         ZipOutputStream(fos).use { zos ->
48             input.walk().filter { it != input }.forEach {
49                 zip(it, it.relativeTo(input).path, zos)
50             }
51         }
52     }
53 }