mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Better compression - decompression implementation
This commit is contained in:
@@ -86,18 +86,13 @@ class BinaryAttachment : Parcelable {
|
|||||||
// To compress, create a new binary with file
|
// To compress, create a new binary with file
|
||||||
if (isCompressed != true) {
|
if (isCompressed != true) {
|
||||||
val fileBinaryCompress = File(concreteDataFile.parent, concreteDataFile.name + "_temp")
|
val fileBinaryCompress = File(concreteDataFile.parent, concreteDataFile.name + "_temp")
|
||||||
var outputStream: GZIPOutputStream? = null
|
GZIPOutputStream(FileOutputStream(fileBinaryCompress)).use { outputStream ->
|
||||||
var inputStream: InputStream? = null
|
getInputDataStream().use { inputStream ->
|
||||||
try {
|
|
||||||
outputStream = GZIPOutputStream(FileOutputStream(fileBinaryCompress))
|
|
||||||
inputStream = getInputDataStream()
|
|
||||||
inputStream.readBytes(bufferSize) { buffer ->
|
inputStream.readBytes(bufferSize) { buffer ->
|
||||||
outputStream.write(buffer)
|
outputStream.write(buffer)
|
||||||
}
|
}
|
||||||
} finally {
|
}
|
||||||
inputStream?.close()
|
}
|
||||||
outputStream?.close()
|
|
||||||
|
|
||||||
// Remove unGzip file
|
// Remove unGzip file
|
||||||
if (concreteDataFile.delete()) {
|
if (concreteDataFile.delete()) {
|
||||||
if (fileBinaryCompress.renameTo(concreteDataFile)) {
|
if (fileBinaryCompress.renameTo(concreteDataFile)) {
|
||||||
@@ -105,7 +100,8 @@ class BinaryAttachment : Parcelable {
|
|||||||
isCompressed = true
|
isCompressed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
isCompressed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,18 +111,13 @@ class BinaryAttachment : Parcelable {
|
|||||||
dataFile?.let { concreteDataFile ->
|
dataFile?.let { concreteDataFile ->
|
||||||
if (isCompressed != false) {
|
if (isCompressed != false) {
|
||||||
val fileBinaryDecompress = File(concreteDataFile.parent, concreteDataFile.name + "_temp")
|
val fileBinaryDecompress = File(concreteDataFile.parent, concreteDataFile.name + "_temp")
|
||||||
var outputStream: FileOutputStream? = null
|
FileOutputStream(fileBinaryDecompress).use { outputStream ->
|
||||||
var inputStream: GZIPInputStream? = null
|
GZIPInputStream(getInputDataStream()).use { inputStream ->
|
||||||
try {
|
|
||||||
outputStream = FileOutputStream(fileBinaryDecompress)
|
|
||||||
inputStream = GZIPInputStream(getInputDataStream())
|
|
||||||
inputStream.readBytes(bufferSize) { buffer ->
|
inputStream.readBytes(bufferSize) { buffer ->
|
||||||
outputStream.write(buffer)
|
outputStream.write(buffer)
|
||||||
}
|
}
|
||||||
} finally {
|
}
|
||||||
inputStream?.close()
|
}
|
||||||
outputStream?.close()
|
|
||||||
|
|
||||||
// Remove gzip file
|
// Remove gzip file
|
||||||
if (concreteDataFile.delete()) {
|
if (concreteDataFile.delete()) {
|
||||||
if (fileBinaryDecompress.renameTo(concreteDataFile)) {
|
if (fileBinaryDecompress.renameTo(concreteDataFile)) {
|
||||||
@@ -134,7 +125,8 @@ class BinaryAttachment : Parcelable {
|
|||||||
isCompressed = false
|
isCompressed = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
isCompressed = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user