-
-
Save trunghq3101/788fdf174d1ea2f51cc398155bea21ae to your computer and use it in GitHub Desktop.
Zlib Inflate/Decompress in Kotlin
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
| /** | |
| * Zlib decompress a file and return its contents | |
| * | |
| * @param filePath absolute path to file | |
| * @return unzipped file contents | |
| */ | |
| fun decompress(filePath: String) : String { | |
| val content = File(filePath).readBytes() | |
| val inflater = Inflater() | |
| val outputStream = ByteArrayOutputStream() | |
| val buffer = ByteArray(1024) | |
| inflater.setInput(content) | |
| while (!inflater.finished()) { | |
| val count = inflater.inflate(buffer) | |
| outputStream.write(buffer, 0, count) | |
| } | |
| outputStream.close() | |
| return outputStream.toString(UTF_8) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment