+htp add shortcuts for quick encoding / decoding
This commit is contained in:
parent
0b1dd68eaf
commit
2a37831937
4 changed files with 8 additions and 5 deletions
|
|
@ -65,8 +65,8 @@ class DeflateSpec extends WordSpec with CodecSpecSupport {
|
|||
}
|
||||
}
|
||||
|
||||
def ourDeflate(bytes: ByteString): ByteString = Deflate.newCompressor.compressAndFinish(bytes)
|
||||
def ourInflate(bytes: ByteString): ByteString = Deflate.newDecompressor.decompress(bytes)
|
||||
def ourDeflate(bytes: ByteString): ByteString = Deflate.encode(bytes)
|
||||
def ourInflate(bytes: ByteString): ByteString = Deflate.decode(bytes)
|
||||
|
||||
def streamDeflate(bytes: ByteString) = {
|
||||
val output = new ByteArrayOutputStream()
|
||||
|
|
|
|||
|
|
@ -103,8 +103,8 @@ class GzipSpec extends WordSpec with CodecSpecSupport {
|
|||
}
|
||||
|
||||
def gzip(s: String) = ourGzip(ByteString(s, "UTF8"))
|
||||
def ourGzip(bytes: ByteString): ByteString = Gzip.newCompressor.compressAndFinish(bytes)
|
||||
def ourGunzip(bytes: ByteString): ByteString = Gzip.newDecompressor.decompressAndFinish(bytes)
|
||||
def ourGzip(bytes: ByteString): ByteString = Gzip.encode(bytes)
|
||||
def ourGunzip(bytes: ByteString): ByteString = Gzip.decode(bytes)
|
||||
|
||||
lazy val corruptGzipContent = {
|
||||
val content = gzip("Hello").toArray
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ trait Decoder {
|
|||
def decodeData[T](t: T)(implicit mapper: DataMapper[T]): T =
|
||||
mapper.transformDataBytes(t, newDecodeTransfomer)
|
||||
|
||||
def decode(input: ByteString): ByteString = newDecompressor.decompressAndFinish(input)
|
||||
|
||||
def newDecompressor: Decompressor
|
||||
|
||||
def newDecodeTransfomer(): Flow[ByteString, ByteString] = {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
package akka.http.coding
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import akka.http.model._
|
||||
import akka.http.util.StreamUtils
|
||||
import akka.util.ByteString
|
||||
|
|
@ -24,6 +23,8 @@ trait Encoder {
|
|||
def encodeData[T](t: T)(implicit mapper: DataMapper[T]): T =
|
||||
mapper.transformDataBytes(t, newEncodeTransformer)
|
||||
|
||||
def encode(input: ByteString): ByteString = newCompressor.compressAndFinish(input)
|
||||
|
||||
def newCompressor: Compressor
|
||||
|
||||
def newEncodeTransformer(): Flow[ByteString, ByteString] = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue