Socket
Socket
Sign inDemoInstall

file-system

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-system - npm Package Compare versions

Comparing version 1.2.6 to 1.2.7

test/base64.js

3

Gruntfile.js

@@ -8,3 +8,4 @@ module.exports = function(grunt) {

'vendor/**/*.js',
'./*.js'
'./*.js',
'!./test.js'
]

@@ -11,0 +12,0 @@ }

@@ -370,2 +370,36 @@ /**

});
};
function base64(filename, data) {
var extname = path.extname(filename).substr(1);
extname = extname || 'png';
var baseType = {
jpg: 'jpeg'
};
var type = baseType[extname] ? baseType[extname] : extname;
return 'data:image/' + type + ';base64,' + new Buffer(data, 'binary').toString('base64');
}
/**
* @description
* Get image file base64 data
*/
exports.base64 = function(filename, callback) {
if (!callback) callback = util.noop;
fs.readFile(filename, { encoding: 'binary' }, function(err, data) {
if (err) return callback(err);
callback(null, base64(filename, data));
});
};
/**
* @description
* The api same as base64, but it's synchronous
*/
exports.base64Sync = function(filename) {
var data = fs.readFileSync(filename);
return base64(filename, data);
};
{
"name": "file-system",
"version": "1.2.6",
"version": "1.2.7",
"description": "Strengthen the ability of file system",

@@ -19,3 +19,4 @@ "main": "index.js",

"maker",
"node file"
"node file",
"base64"
],

@@ -22,0 +23,0 @@ "author": "douzi <liaowei08@gmail.com>",

@@ -66,13 +66,3 @@ # file-system — Simplified file system

```
#### filter description
* `*.js` only match js files in current dir.
* `**/*.js` match all js files.
* `path/*.js` match js files in path.
* `!*.js` exclude js files in current dir.
* ``.{jpg,png,gif}`` means jpg, png or gif
```
'**/*' // Match all files
'!**/*.js' // Exclude all js files
'**/*.{jpg,png,gif}' // Match jpg, png, or gif files
```
[filter params description](https://github.com/douzi8/file-match#filter-description)

@@ -123,2 +113,14 @@ ### file.recurseSync

file.copySync('path', 'path', { filter: ['*.html.js'], process: function(contents, filepath) {} });
```
### file.base64
Read image file, callback with base64 data
```js
file.base64('img.png', function(err, data) {
});
```
### file.base64Sync
```js
var base64 = file.base64Sync('img.png');
```
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