elkozmon / zoonavigator

Web-based ZooKeeper UI / editor / browser
https://zoonavigator.elkozmon.com
GNU Affero General Public License v3.0
506 stars 72 forks source link

Support reading GZipped data #26

Closed jhalterman closed 5 years ago

jhalterman commented 5 years ago

Similar to #24 :) It would be great if Zoonavigator supported reading and writing GZipped data. This should be fairly easy to do since it already supports JSON. Ex (in Scala, but you get the idea, using Jackson to deserialize Gzipped data):

def readGzippedOrCreateObjectNode(data: Array[Byte]): ObjectNode = {
  // See https://tools.ietf.org/html/rfc1952
  val isGzip: Boolean = data != null && data.length > 3 && data(0) == 31 && data(1) == -117 && data(2) == 8

  if (data == null) {
    mapper.createObjectNode()
  } else if (isGzip) {
    Try(mapper.readValue(new GZIPInputStream(new ByteArrayInputStream(data)), classOf[ObjectNode])).getOrElse(mapper.createObjectNode())
  } else {
    readOrCreateObjectNode(data)
  }
}

def compress(data: Array[Byte]): Array[Byte] = {
  val bytes: ByteArrayOutputStream = new ByteArrayOutputStream
  val out: GZIPOutputStream = new GZIPOutputStream(bytes)

  try {
    out.write(data)
  } finally {
    out.close()
  }

  bytes.toByteArray
}
elkozmon commented 5 years ago

Alright, sounds easy enough! It will be included in the next release very soon :)

elkozmon commented 5 years ago

Hey :) I just released version 0.6.0. There is a new select button in data editor where you can pick compression method (only gzip for now) and read/write compressed data. If you open up a node with already compressed data the editor should detect this and switch to the appropriate compression automatically.