Data-JPack
view release on metacpan or search on metacpan
$packer->encode($data);
Single call that wraps and encodes data suitable for storing in a
standalone file, or embeded if the $packer object is conifigured.
Returns the encoded data.
decode
$packer->decode($data);
Decodes $data expected in Data::JPack format. Returns the decoded data.
encode_file
$packer->encode_file($path);
Single call the encodes the data from a file located and $path. Calls
"encode" internally.
Returns the encoded data.
Streaming Encoding
file, or embeded if the `$packer` object is conifigured.
Returns the encoded data.
### decode
```
$packer->decode($data);
```
Decodes `$data` expected in [Data::JPack](https://metacpan.org/pod/Data%3A%3AJPack) format. Returns the decoded data.
### encode\_file
```
$packer->encode_file($path);
```
Single call the encodes the data from a file located and `$path`. Calls
`encode` internally.
lib/Data/JPack.pm view on Meta::CPAN
my @items=split /\s*,\s*/, $js;
my %pairs= map {s/^\s+//; s/\s+$//;$_ }
map {split ":", $_} @items;
for(keys %pairs){
if(/compression/){
$pairs{$_}=~/"(.*)"/;
$compression=$1;
}
}
my $decoded;
my $output="";
for($compression){
if(/deflate/){
$decoded=decode_base64($data);
rawinflate(\$decoded, \$output) or die $RawInflateError;
}
else {
$output=decode_base64($data);
}
}
$output;
}
sub jpack_decode {
lib/Data/JPack.pod view on Meta::CPAN
Single call that wraps and encodes data suitable for storing in a standalone
file, or embeded if the C<$packer> object is conifigured.
Returns the encoded data.
=head3 decode
$packer->decode($data);
Decodes C<$data> expected in L<Data::JPack> format. Returns the decoded data.
=head3 encode_file
$packer->encode_file($path);
Single call the encodes the data from a file located and C<$path>. Calls
C<encode> internally.
Returns the encoded data.
share/js/02-chunkloader.js view on Meta::CPAN
*/
_decodeChunk(e){
switch(e.options.jpack_type){
case "app":
case "data":
case "boot":
//console.log("SENDING DATA");
//console.log(e.dataFunc());
return this.pool.queueFunction("decode",{options:e.options,string:e.dataFunc()},[])
.then((res)=>{
//res.result is the decoded chunk data to now send to channel manager
return Promise.resolve(res.result);
})
break;
default:
break;
}
}
/**
* Queues a request to download a chunk script. As chunks are large and the
* order is important, a limited number of chunks are downloaded at one time
*
* Returns a promise when the chunkscript has been downloaded, prased and
* decoded. The promise resolves to an arraybuffer of the decoded data
*
* PATHS ARE RELATIVE TO BUILD ROOT ie this.buildRoot
* This is to match the build output paths of the jpack files
*/
queueChunkScript(path){
//Add this to the queue
let promise;
let entry={path:path, dataFunc:undefined};
entry.promise=new Promise((resolve,reject)=>{
entry.resolver=resolve;
entry.rejecter=reject;
});
this.urlQueue.push(entry);
this.urlMap[path]=entry;
this._executeNext();
//This promise is resolved when the script is ready to be decoded
//ie when the dataFunc field has been assigned
return entry.promise
.then((e)=>{
//Queue the decoding into the worker pool
//console.log("ABOUT TO _decodeChunk");
return this._decodeChunk(e);
});
}
_executeNext(){
( run in 2.874 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )