Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"@types/jsonpath": "^0.2.0",
"@types/lodash": "^4.14.171",
"@types/node": "14.14.10",
"@types/pako": "^2.0.0",
"@types/react": "^18.0.20",
"@types/react-dom": "^18.0.5",
"@types/react-redux": "^7.1.12",
Expand Down Expand Up @@ -244,6 +245,7 @@
"jsonpath": "^1.1.1",
"lodash": "^4.17.21",
"lz4js": "^0.2.0",
"pako": "^2.1.0",
"php-serialize": "^4.0.2",
"rawproto": "^0.7.6",
"react": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum Compressor {
LZ4 = 'LZ4',
SNAPPY = 'SNAPPY',
Brotli = 'Brotli',
PHPGZCompress = 'PHPGZCompress',
}

@Entity('database_instance')
Expand Down
3 changes: 2 additions & 1 deletion redisinsight/ui/src/constants/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export enum KeyValueCompressor {
LZ4 = 'LZ4',
SNAPPY = 'SNAPPY',
Brotli = 'Brotli',
// PHPGZCompress = 'PHPGZCompress',
PHPGZCompress = 'PHPGZCompress',
}

export const COMPRESSOR_MAGIC_SYMBOLS: ICompressorMagicSymbols = Object.freeze({
Expand All @@ -196,6 +196,7 @@ export const COMPRESSOR_MAGIC_SYMBOLS: ICompressorMagicSymbols = Object.freeze({
[KeyValueCompressor.LZ4]: '4,34,77,24', // 04 22 4d 18 hex
[KeyValueCompressor.SNAPPY]: '', // no magic symbols
[KeyValueCompressor.Brotli]: '', // no magic symbols
[KeyValueCompressor.PHPGZCompress]: '', // no magic symbols
})

export type ICompressorMagicSymbols = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ const DbCompressor = (props: Props) => {
{
value: KeyValueCompressor.Brotli,
inputDisplay: 'Brotli'
}
},
{
value: KeyValueCompressor.PHPGZCompress,
inputDisplay: 'PHP GZCompress'
},
]

const handleChangeDbCompressorCheckbox = (e: ChangeEvent<HTMLInputElement>): void => {
Expand Down
16 changes: 15 additions & 1 deletion redisinsight/ui/src/utils/decompressors/decompressors.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { forIn } from 'lodash'
import { unzip } from 'gzip-js'
import { decompress as decompressFzstd } from 'fzstd'
// @ts-ignore
import { decompress as decompressLz4 } from 'lz4js'
import { decompress as decompressSnappy } from '@stablelib/snappy'
// @ts-ignore
import { decompress as decompressBrotli } from 'brotli-unicode/js'
import { inflate } from 'pako'
import { COMPRESSOR_MAGIC_SYMBOLS, ICompressorMagicSymbols, KeyValueCompressor } from 'uiSrc/constants'
import { RedisResponseBuffer, RedisString } from 'uiSrc/slices/interfaces'
import { anyToBuffer, bufferToString, isEqualBuffers, Nullable } from 'uiSrc/utils'
import { anyToBuffer, bufferToString, bufferToUint8Array, isEqualBuffers, Nullable } from 'uiSrc/utils'

const decompressingBuffer = (
reply: RedisResponseBuffer,
Expand Down Expand Up @@ -66,6 +69,17 @@ const decompressingBuffer = (
isCompressed: !isEqualBuffers(value, reply),
}
}
case KeyValueCompressor.PHPGZCompress: {
const decompressedValue = inflate(bufferToUint8Array(reply))
if (!decompressedValue) return { value: reply, compressor: null, isCompressed: false }

const value = anyToBuffer(decompressedValue)
return {
value,
compressor,
isCompressed: !isEqualBuffers(value, reply),
}
}
default: {
return { value: reply, compressor: null, isCompressed: false }
}
Expand Down
6 changes: 4 additions & 2 deletions redisinsight/ui/src/utils/formatters/bufferFormatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ const ASCIIToBuffer = (strInit: string) => {
return anyToBuffer(Array.from(Buffer.from(result, 'hex')))
}

const bufferToUTF8 = (reply: RedisResponseBuffer): string => decoder.decode(new Uint8Array(reply.data))
const bufferToUint8Array = (reply: RedisResponseBuffer): Uint8Array => new Uint8Array(reply.data)
const bufferToUTF8 = (reply: RedisResponseBuffer): string => decoder.decode(bufferToUint8Array(reply))

const UintArrayToString = (reply: UintArray): string => decoder.decode(new Uint8Array(reply))

Expand Down Expand Up @@ -138,7 +139,7 @@ const hexToBuffer = (data: string): RedisResponseBuffer => {
}

const bufferToJava = (reply: RedisResponseBuffer) => {
const stream = new ObjectInputStream(new Uint8Array(reply.data))
const stream = new ObjectInputStream(bufferToUint8Array(reply))
const decoded = stream.readObject()
const { fields } = decoded
const fieldsArray = Array.from(fields, ([key, value]) => ({ [key]: value }))
Expand Down Expand Up @@ -172,6 +173,7 @@ export {
ASCIIToBuffer,
isEqualBuffers,
stringToBuffer,
bufferToUint8Array,
bufferToString,
UintArrayToString,
hexToBuffer,
Expand Down
3 changes: 3 additions & 0 deletions redisinsight/ui/src/utils/tests/decompressors/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ export const SNAPPY_COMPRESSED_VALUE_2 = [1, 0, 50]

export const BROTLI_COMPRESSED_VALUE_1 = [49, 65, 76, 231, 187, 141, 68]
export const BROTLI_COMPRESSED_VALUE_2 = [49, 65, 76, 231, 191, 141, 68]

export const PHPGZCOMPRESS_COMPRESSED_VALUE_1 = [120, 156, 51, 4, 0, 0, 50, 0, 50]
export const PHPGZCOMPRESS_COMPRESSED_VALUE_2 = [120, 156, 51, 2, 0, 0, 51, 0, 51]
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
SNAPPY_COMPRESSED_VALUE_1,
BROTLI_COMPRESSED_VALUE_1,
BROTLI_COMPRESSED_VALUE_2,
PHPGZCOMPRESS_COMPRESSED_VALUE_1,
PHPGZCOMPRESS_COMPRESSED_VALUE_2,
} from './constants'

const defaultValues = [
Expand Down Expand Up @@ -129,6 +131,22 @@ const defaultValues = [
outputStr: DECOMPRESSED_VALUE_STR_2,
isCompressed: true,
},
{
input: PHPGZCOMPRESS_COMPRESSED_VALUE_1,
compressor: KeyValueCompressor.PHPGZCompress,
compressorInit: KeyValueCompressor.PHPGZCompress,
output: DECOMPRESSED_VALUE_1,
outputStr: DECOMPRESSED_VALUE_STR_1,
isCompressed: true,
},
{
input: PHPGZCOMPRESS_COMPRESSED_VALUE_2,
compressor: KeyValueCompressor.PHPGZCompress,
compressorInit: KeyValueCompressor.PHPGZCompress,
output: DECOMPRESSED_VALUE_2,
outputStr: DECOMPRESSED_VALUE_STR_2,
isCompressed: true,
},
].map((value) => ({
...value,
input: anyToBuffer(value.input)
Expand All @@ -139,7 +157,10 @@ describe('getCompressor', () => {
let expected = compressorByValue || compressor

// SNAPPY doesn't have magic symbols
if (compressor === KeyValueCompressor.SNAPPY || compressor === KeyValueCompressor.Brotli) {
if (compressor === KeyValueCompressor.SNAPPY
|| compressor === KeyValueCompressor.Brotli
|| compressor === KeyValueCompressor.PHPGZCompress
) {
expected = null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
bufferToHex,
bufferToBinary,
binaryToBuffer,
bufferToJava
bufferToJava,
bufferToUint8Array,
} from 'uiSrc/utils'

const defaultValues = [
Expand Down Expand Up @@ -141,3 +142,9 @@ describe('bufferToJava', () => {
expect(bufferToJava(input)).toEqual(expected)
})
})

describe('bufferToUint8Array', () => {
test.each(javaValues)('%o', ({ uint8Array }) => {
expect(bufferToUint8Array(anyToBuffer(uint8Array))).toEqual(new Uint8Array(uint8Array))
})
})
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2674,6 +2674,11 @@
resolved "https://registry.yarnpkg.com/@types/numeral/-/numeral-0.0.28.tgz#e43928f0bda10b169b6f7ecf99e3ddf836b8ebe4"
integrity sha512-Sjsy10w6XFHDktJJdXzBJmoondAKW+LcGpRFH+9+zXEDj0cOH8BxJuZA9vUDSMAzU1YRJlsPKmZEEiTYDlICLw==

"@types/pako@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/pako/-/pako-2.0.0.tgz#12ab4c19107528452e73ac99132c875ccd43bdfb"
integrity sha512-10+iaz93qR5WYxTo+PMifD5TSxiOtdRaxBf7INGGXMQgTCu8Z/7GYWYFUOS3q/G0nE5boj1r4FEB+WSy7s5gbA==

"@types/parse-json@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
Expand Down Expand Up @@ -12390,6 +12395,11 @@ p-try@^2.0.0:
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==

pako@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86"
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==

pako@~1.0.2, pako@~1.0.5:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
Expand Down