mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-13 06:38:52 +02:00
ef4c5eb65e
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
18 lines
716 B
Scala
18 lines
716 B
Scala
package com.twitter.graph_feature_service.server.modules
|
|
|
|
import com.twitter.bijection.Injection
|
|
import scala.util.Try
|
|
import net.jpountz.lz4.{LZ4CompressorWithLength, LZ4DecompressorWithLength, LZ4Factory}
|
|
|
|
object LZ4Injection extends Injection[Array[Byte], Array[Byte]] {
|
|
private val lz4Factory = LZ4Factory.fastestInstance()
|
|
private val fastCompressor = new LZ4CompressorWithLength(lz4Factory.fastCompressor())
|
|
private val decompressor = new LZ4DecompressorWithLength(lz4Factory.fastDecompressor())
|
|
|
|
override def apply(a: Array[Byte]): Array[Byte] = LZ4Injection.fastCompressor.compress(a)
|
|
|
|
override def invert(b: Array[Byte]): Try[Array[Byte]] = Try {
|
|
LZ4Injection.decompressor.decompress(b)
|
|
}
|
|
}
|