| Server IP : 68.183.124.220 / Your IP : 216.73.217.137 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/gavin/workspace/readjs/node_modules/libbase64/ |
Upload File : |
# libbase64
Encode and decode base64 strings.
## Usage
Install with npm
npm install libbase64
Require in your script
```javascript
var libbase64 = require('libbase64');
```
### Encode values
Encode Buffer objects or unicode strings with
libbase64.encode(val) → String
Where
* **val** is a Buffer or an unicode string
**Example**
```javascript
libbase64.encode('jõgeva');
// asO1Z2V2YQ==
```
### Wrap encoded values
To enforce soft line breaks on lines longer than selected amount of characters, use `wrap`
libbase64.wrap(str[, lineLength]) → String
Where
* **str** is a base64 encoded string
* **lineLength** (defaults to 76) is the maximum allowed line length
**Example**
```javascript
libbase64.wrap('asO1Z2V2asO1Z2V2asO1Z2V2YQ==', 10)
// asO1Z2V2as\r\n
// O1Z2V2asO1\r\n
// Z2V2YQ==
```
### Transform Streams
`libbase64` makes it possible to encode and decode streams with `libbase64.Encoder` and `libbase64.Decoder` constructors.
### Encoder Stream
Create new Encoder Stream with
var encoder = new libbase64.Encoder([options])
Where
* **options** is the optional stream options object with an additional option `lineLength` if you want to use any other line length than the default 76 characters (or set to `false` to turn the soft wrapping off completely)
**Example**
The following example script reads in a file, encodes it to base64 and saves the output to a file.
```javascript
var libbase64 = require('libbase64');
var fs = require('fs');
var source = fs.createReadStream('source.txt');
var encoded = fs.createReadStream('encoded.txt');
var encoder = new libbase64.Encoder();
source.pipe(encoder).pipe(encoded);
```
### Decoder Stream
Create new Decoder Stream with
var decoder = new libbase64.Decoder([options])
Where
* **options** is the optional stream options object
**Example**
The following example script reads in a file in base64 encoding, decodes it and saves the output to a file.
```javascript
var libbase64 = require('libbase64');
var fs = require('fs');
var encoded = fs.createReadStream('encoded.txt');
var dest = fs.createReadStream('dest.txt');
var decoder = new libbase64.Decoder();
encoded.pipe(decoder).pipe(dest);
```
## License
**MIT**