Socket
Socket
Sign inDemoInstall

hexo-util

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hexo-util - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

lib/cache_stream.js

1

lib/index.js

@@ -19,1 +19,2 @@ 'use strict';

exports.HashStream = hash.HashStream;
exports.CacheStream = require('./cache_stream');

38

lib/spawn.js

@@ -5,2 +5,3 @@ 'use strict';

var Promise = require('bluebird');
var CacheStream = require('./cache_stream');

@@ -22,24 +23,15 @@ module.exports = function(command, args, options) {

var encoding = options.hasOwnProperty('encoding') ? options.encoding : 'utf8';
var stdout = [];
var stdoutLength = 0;
var stderr = [];
var stderrLength = 0;
var stdoutCache = new CacheStream();
var stderrCache = new CacheStream();
var stdout = task.stdout.pipe(stdoutCache);
var stderr = task.stderr.pipe(stderrCache);
task.stdout.on('data', function(data) {
stdout.push(data);
stdoutLength += data.length;
if (verbose) {
stdout = stdout.pipe(process.stdout);
stderr = stderr.pipe(process.stderr);
}
if (verbose) process.stdout.write(data);
});
task.stderr.on('data', function(data) {
stderr.push(data);
stderrLength += data.length;
if (verbose) process.stderr.write(data);
});
task.on('close', function(code) {
if (code) {
var e = new Error(concatBuffer(stderr, stderrLength, encoding));
var e = new Error(getCache(stderrCache, encoding));
e.code = code;

@@ -50,3 +42,3 @@

resolve(concatBuffer(stdout, stdoutLength, encoding));
resolve(getCache(stdoutCache, encoding));
});

@@ -56,7 +48,7 @@ });

function concatBuffer(buffer, length, encoding) {
var data = Buffer.concat(buffer, length);
if (!encoding) return data;
function getCache(stream, encoding) {
var buf = stream.getCache();
if (!encoding) return buf;
return data.toString(encoding);
return buf.toString(encoding);
}
{
"name": "hexo-util",
"version": "0.3.0",
"version": "0.4.0",
"description": "Utilities for Hexo.",

@@ -31,3 +31,4 @@ "main": "lib/index",

"jscs-preset-hexo": "^1.0.1",
"mocha": "^2.3.4"
"mocha": "^2.3.4",
"rewire": "^2.5.1"
},

@@ -34,0 +35,0 @@ "dependencies": {

@@ -19,2 +19,20 @@ # hexo-util

### CacheStream()
Caches contents piped to the stream.
``` js
var stream = new CacheStream();
fs.createReadStream('/path/to/file').pipe(stream);
stream.on('finish', function(){
// Read cache piped to the stream
console.log(stream.getCache());
// Destroy cache
stream.destroy();
});
```
### escapeRegex(str)

@@ -218,2 +236,2 @@

[Hexo]: http://hexo.io/
[Hexo]: http://hexo.io/
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