base64
object base64
Functions for working with base 64.
Value members
Concrete methods
Converts a stream of base 64 text in to a stream of bytes.
Converts a stream of base 64 text in to a stream of bytes.
If the text is not valid base 64, the pipe fails with an exception. Padding characters at the end of the input stream are optional, but if present, must be valid per the base 64 specification. Whitespace characters are ignored.
The default base 64 alphabet is used by this pipe.
State.this._1
case1=>
State.this._2
case2=>
State.this._3
case_=>
thrownewIndexOutOfBoundsException(n.toString())
}
}
objectStateextendsAnyRefwithProduct{
overridedeftoString:String="State"
typeMirroredMonoType
deffromProduct(`x$0₃`:Product):MirroredMonoType=newState(`x$0₃`.productElement(0).$asInstanceOf$[Int],`x$0₃`.productElement(1).$asInstanceOf$[Int],`x$0₃`.productElement(2).$asInstanceOf$[Int])
}
valPad:Char=alphabet.pad
defpaddingError:Left[String,Nothing]=Left.apply[String,Nothing]("Malformedpadding-finalquantummayoptionallybepaddedwithoneortwopaddingcharacterssuchthatthequantumiscompleted")
defdecode(state:State,str:String):Either[String,Tuple2[State,Chunk[Byte]]]={
var`buffer₂`:Int=state.buffer
var`mod₂`:Int=state.mod
var`padding₂`:Int=state.padding
varidx:Int=0
varbidx:Int=0
val`acc₂`:Array[Byte]=newArray[Byte](augmentString(str).size.+(3)./(4).*(3))
while(idx.<(str.length())){
augmentString(str).apply(idx)match{
casecifalphabet.ignore(c)=>
()
casec=>
valcidx:Int=if(`padding₂`.==(0))if(`c₂`.==(Pad))if(`mod₂`.==(2).||(`mod₂`.==(3))){
`padding₂`=`padding₂`.+(1)
0
}elsereturnpaddingErrorelsetryalphabet.toIndex(`c₂`)catch{
case_:IllegalArgumentException=>
returnLeft.apply[String,Nothing](_root_.scala.StringContext.apply("Invalidbase64character\'","\'atindex","").s(`c₂`,idx))
}elseif(`c₂`.==(Pad))if(`padding₂`.==(1).&&(`mod₂`.==(3))){
`padding₂`=`padding₂`.+(1)
0
}elsereturnpaddingErrorelsereturnLeft.apply[String,Nothing](_root_.scala.StringContext.apply("Unexpectedcharacter\'","\'atindex","afterpaddingcharacter;only\'=\'andwhitespacecharactersallowedafterfirstpaddingcharacter").s(`c₂`,idx))
`mod₂`match{
case0=>
`buffer₂`=cidx.&(63)
`mod₂`=`mod₂`.+(1)
case(1|2)=>
`buffer₂`=`buffer₂`.<<(6).|(cidx.&(63))
`mod₂`=`mod₂`.+(1)
case3=>
`buffer₂`=`buffer₂`.<<(6).|(cidx.&(63))
`mod₂`=0
`acc₂`.update(bidx,`buffer₂`.>>(16).toByte)
`acc₂`.update(bidx.+(1),`buffer₂`.>>(8).toByte)
`acc₂`.update(bidx.+(2),`buffer₂`.toByte)
bidx=bidx.+(3)
}
}
idx=idx.+(1)
}
valpaddingInBuffer:Int=if(`mod₂`.==(0))`padding₂`else0
valout:Chunk[Byte]=Chunk.byteVector(ByteVector.view(`acc₂`).take(bidx.-(paddingInBuffer).toLong))
valcarry:State=State.apply(`buffer₂`,`mod₂`,`padding₂`)
Right.apply[Nothing,Tuple2[State,Chunk[Byte]]](Tuple2.apply[State,Chunk[Byte]](carry,out))
}
deffinish(`state₂`:State):Either[String,Chunk[Byte]]=if(`state₂`.padding.!=(0).&&(`state₂`.mod.!=(0)))paddingErrorelse`state₂`.modmatch{
case0=>
Right.apply[Nothing,Chunk[Nothing]](Chunk.empty[Nothing])
case1=>
Left.apply[String,Nothing]("Finalbase64quantumhadonly1digit-musthaveatleast2digits")
case2=>
Right.apply[Nothing,Chunk[Byte]](Chunk.apply[Byte](`state₂`.buffer.>>(4).toByte))
case3=>
val`buffer₃`:Int=`state₂`.buffer
Right.apply[Nothing,Chunk[Byte]](Chunk.apply[Byte](`buffer₃`.>>(10).toByte,`buffer₃`.>>(2).toByte))
}
defgo(`state₃`:State,s:Stream[F,String]):Pull[F,Byte,Unit]=InvariantOps[F,String](s).pull.uncons1.flatMap[F,Byte,Unit](((x$1:Option[Tuple2[String,Stream[F,String]]])=>x$1match{
caseSome(Tuple2(hd,tl))=>
decode(`state₃`,hd)match{
caseRight(Tuple2(newState,out))=>
Pull.output[Nothing,Byte](`out₂`).>>[F,Byte,Unit](go(newState,tl))
caseLeft(err)=>
Pull.raiseError[F](newIllegalArgumentException(err))(evidence$6)
}
caseNone=>
finish(`state₃`)match{
caseRight(out)=>
Pull.output[Nothing,Byte](`out₃`)
caseLeft(err)=>
Pull.raiseError[F](newIllegalArgumentException(`err₂`))(evidence$6)
}
}))
((in:Stream[F,String])=>StreamPullOps[F,Byte](go(State.apply(0,0,0),in)).stream)
}" class="documentableAnchor">
def
State.this._1
case1=>
State.this._2
case2=>
State.this._3
case_=>
thrownewIndexOutOfBoundsException(n.toString())
}
}
objectStateextendsAnyRefwithProduct{
overridedeftoString:String="State"
typeMirroredMonoType
deffromProduct(`x$0₃`:Product):MirroredMonoType=newState(`x$0₃`.productElement(0).$asInstanceOf$[Int],`x$0₃`.productElement(1).$asInstanceOf$[Int],`x$0₃`.productElement(2).$asInstanceOf$[Int])
}
valPad:Char=alphabet.pad
defpaddingError:Left[String,Nothing]=Left.apply[String,Nothing]("Malformedpadding-finalquantummayoptionallybepaddedwithoneortwopaddingcharacterssuchthatthequantumiscompleted")
defdecode(state:State,str:String):Either[String,Tuple2[State,Chunk[Byte]]]={
var`buffer₂`:Int=state.buffer
var`mod₂`:Int=state.mod
var`padding₂`:Int=state.padding
varidx:Int=0
varbidx:Int=0
val`acc₂`:Array[Byte]=newArray[Byte](augmentString(str).size.+(3)./(4).*(3))
while(idx.<(str.length())){
augmentString(str).apply(idx)match{
casecifalphabet.ignore(c)=>
()
casec=>
valcidx:Int=if(`padding₂`.==(0))if(`c₂`.==(Pad))if(`mod₂`.==(2).||(`mod₂`.==(3))){
`padding₂`=`padding₂`.+(1)
0
}elsereturnpaddingErrorelsetryalphabet.toIndex(`c₂`)catch{
case_:IllegalArgumentException=>
returnLeft.apply[String,Nothing](_root_.scala.StringContext.apply("Invalidbase64character\'","\'atindex","").s(`c₂`,idx))
}elseif(`c₂`.==(Pad))if(`padding₂`.==(1).&&(`mod₂`.==(3))){
`padding₂`=`padding₂`.+(1)
0
}elsereturnpaddingErrorelsereturnLeft.apply[String,Nothing](_root_.scala.StringContext.apply("Unexpectedcharacter\'","\'atindex","afterpaddingcharacter;only\'=\'andwhitespacecharactersallowedafterfirstpaddingcharacter").s(`c₂`,idx))
`mod₂`match{
case0=>
`buffer₂`=cidx.&(63)
`mod₂`=`mod₂`.+(1)
case(1|2)=>
`buffer₂`=`buffer₂`.<<(6).|(cidx.&(63))
`mod₂`=`mod₂`.+(1)
case3=>
`buffer₂`=`buffer₂`.<<(6).|(cidx.&(63))
`mod₂`=0
`acc₂`.update(bidx,`buffer₂`.>>(16).toByte)
`acc₂`.update(bidx.+(1),`buffer₂`.>>(8).toByte)
`acc₂`.update(bidx.+(2),`buffer₂`.toByte)
bidx=bidx.+(3)
}
}
idx=idx.+(1)
}
valpaddingInBuffer:Int=if(`mod₂`.==(0))`padding₂`else0
valout:Chunk[Byte]=Chunk.byteVector(ByteVector.view(`acc₂`).take(bidx.-(paddingInBuffer).toLong))
valcarry:State=State.apply(`buffer₂`,`mod₂`,`padding₂`)
Right.apply[Nothing,Tuple2[State,Chunk[Byte]]](Tuple2.apply[State,Chunk[Byte]](carry,out))
}
deffinish(`state₂`:State):Either[String,Chunk[Byte]]=if(`state₂`.padding.!=(0).&&(`state₂`.mod.!=(0)))paddingErrorelse`state₂`.modmatch{
case0=>
Right.apply[Nothing,Chunk[Nothing]](Chunk.empty[Nothing])
case1=>
Left.apply[String,Nothing]("Finalbase64quantumhadonly1digit-musthaveatleast2digits")
case2=>
Right.apply[Nothing,Chunk[Byte]](Chunk.apply[Byte](`state₂`.buffer.>>(4).toByte))
case3=>
val`buffer₃`:Int=`state₂`.buffer
Right.apply[Nothing,Chunk[Byte]](Chunk.apply[Byte](`buffer₃`.>>(10).toByte,`buffer₃`.>>(2).toByte))
}
defgo(`state₃`:State,s:Stream[F,String]):Pull[F,Byte,Unit]=InvariantOps[F,String](s).pull.uncons1.flatMap[F,Byte,Unit](((x$1:Option[Tuple2[String,Stream[F,String]]])=>x$1match{
caseSome(Tuple2(hd,tl))=>
decode(`state₃`,hd)match{
caseRight(Tuple2(newState,out))=>
Pull.output[Nothing,Byte](`out₂`).>>[F,Byte,Unit](go(newState,tl))
caseLeft(err)=>
Pull.raiseError[F](newIllegalArgumentException(err))(evidence$6)
}
caseNone=>
finish(`state₃`)match{
caseRight(out)=>
Pull.output[Nothing,Byte](`out₃`)
caseLeft(err)=>
Pull.raiseError[F](newIllegalArgumentException(`err₂`))(evidence$6)
}
}))
((in:Stream[F,String])=>StreamPullOps[F,Byte](go(State.apply(0,0,0),in)).stream)
}" class="documentableName ">decodeWithAlphabet[F[_] : RaiseThrowable](alphabet: Base64Alphabet): (F, String) => Byte
Encodes a byte stream in to a stream of base 64 text. The default base 64 alphabet is used by this pipe.
Encodes a byte stream in to a stream of base 64 text. The default base 64 alphabet is used by this pipe.