blobcode -- binary-to-text encodings and decodings for BLOBs

Supports binary-to-text encodings and decodings for the VCL data type BLOB, which may contain arbitrary data of any length. Currently (as of Varnish 4.1.1), BLOBs may only be used as arguments of VMOD functions; so this module is meant to facilitate the use of other VMODs.


import blobcode [from "path"] ;

sub vcl_init {  
    # Create blob objects from encodings such as base64 or hex.  
    new myblob   = blobcode.blob(decoding=BASE64, encoded="Zm9vYmFy");  
    new yourblob = blobcode.blob(decoding=HEX, encoded="666F6F");  

sub vcl_recv {  
    # The .get() method retrieves the BLOB from an object.  
    set req.http.MyBlob-As-Hex  
        = blobcode.encode(encoding=HEX, blob=myblob.get());

    # The .encode() method efficiently retrieves an encoding.  
    set req.http.YourBlob-As-Base64 = yourblob.encode(BASE64);

    # decode() and encode() functions convert blobs to text and  
    # vice versa at runtime.  
    set req.http.Base64-Encoded  
        = blobcode.encode(BASE64,blobcode.decode(HEX, req.http.Hex-Encoded));

    # transcode() converts from one encoding to another.  
    set req.http.Hex-Encoded  
        = blobcode.transcode(decoding=BASE64, encoding=HEX, "YmF6");  
In development
Varnish version supported: 
Commercial support: