New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-base64-image

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-base64-image - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

test/test.jpg

37

index.js

@@ -17,17 +17,30 @@ 'use strict';

request({url: url, encoding: null}, function (err, res, body) {
if (err) { return callback(err); }
var encoder = function (body, options) {
var image;
if (body && res.statusCode === 200) {
var image;
if (options && options.string === true) {
image = body.toString('base64');
return callback(null, image);
} else {
image = new Buffer(body, 'base64');
return callback(null, image);
}
};
if (options && options.string === true) {
image = body.toString('base64');
return callback(null, image);
} else {
image = new Buffer(body, 'base64');
return callback(null, image);
if (options && options.localFile === true) {
fs.readFile(url, function (err, data) {
if (err) { return callback(err); }
return encoder(data, options);
});
} else {
request({url: url, encoding: null}, function (err, res, body) {
if (err) { return callback(err); }
if (body && res.statusCode === 200) {
return encoder(body, options);
}
}
});
});
}
};

@@ -34,0 +47,0 @@

{
"name": "node-base64-image",
"version": "0.0.1",
"version": "0.1.0",
"description": "Download images from remote URLs and encode/decode them to base64",

@@ -27,3 +27,3 @@ "main": "index.js",

"author": "Riyadh Al Nur <riyadhalnur@verticalaxisbd.com> (http://blog.verticalaxisbd.com)",
"license": "GPLv3",
"license": "MIT",
"dependencies": {

@@ -36,2 +36,2 @@ "request": "^2.51.x"

}
}
}

@@ -6,3 +6,3 @@ [![Build Status](https://travis-ci.org/riyadhalnur/node-base64-image.svg?branch=master)](https://travis-ci.org/riyadhalnur/node-base64-image)

Download images from remote URLs and encode/decode them to base64
Download images from remote URLs or use local images and encode/decode them to base64

@@ -30,5 +30,18 @@ To install

#### Encode a local image
```
var path = __dirname + '/../test.jpg',
options = {localFile: true, string: true};
base64.base64encode(path, function (err, image) {
if (err) { console.log(err); }
console.log(image);
});
```
##### Parameters
url (string) - the url of the image to be downloaded and encoded.
options (object) - if string is passed is with 'true', the image returned will be a base64 string. Otherwise, the base64 buffer is returned.
if localFile is passed is with 'true', a local image instead of a remote one will be used
callback (function) - the callback will contain the err object and the encoded image object.

@@ -38,6 +51,6 @@

```
var options = {filename: 'test'};
var imageData = new Buffer('/9j/4AAQSkZJRgABAQAAAQABAAD...', 'base64');
var options = {filename: 'test'};
var imageData = new Buffer('/9j/4AAQSkZJRgABAQAAAQABAAD...', 'base64');
base64.base64decode(imageData, options, function (err, saved) {
base64.base64decoder(imageData, options, function (err, saved) {
if (err) { console.log(err); }

@@ -48,9 +61,9 @@ console.log(saved);

##### Paramaters
##### Parameters
imageData (buffer) - the base64 image buffer.
options (object) - contains the 'filename' property; this will be the written image file.
callback (function) - the callback will contain the err object and the 'successful save' string.
callback (function) - the callback will contain the err object and the 'successful save' string.
### License
This library is licensed under the GPL v3.0 license.
This library is licensed under the MIT license.

@@ -57,0 +70,0 @@ ### Issues

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc