Skip to content

Instantly share code, notes, and snippets.

View calvinmetcalf's full-sized avatar

Calvin Metcalf calvinmetcalf

View GitHub Profile
@calvinmetcalf
calvinmetcalf / es5-readable.js
Created January 13, 2015 15:35
whatwg readable streams translated to es5
var Promise = global.Promise || require('lie');
function noop(){}
function typeIsObject(x) {
return (typeof x === 'object' && x !== null) || typeof x === 'function';
}
function ExclusiveStreamReader () {
throw new Error('not implimented');
}
function ReadableStream(opts) {
var start = opts.start || noop;
1202300570646949282975778736296044504637420276922119515891306094871931668460784216303271282241030575518881272601473048342313323978822354112723793077063711024799605041573603813703320998650824158507421521304080753824825559800777934959555240878004505128415484380701402975562735440962725636798208731061053333507342894172880477300633322193936363562353666501818198095906153463974431375520074787234456522989009161910713193742753315372158820362468492693545660549966470684922131941091054432999483372852777551384936999767430751223410260597969094931858657675936964111380130223218407897022587673283472205059589528444890959563220757936196324830429676504525491654578487634176890980893848809490613934526895074319424920614913184519893078027588263087579951119469336149532871649846777184859405351609205913028578299617964967141119761768708895654587137000856637081789792351254076954424958436659911181131442061316460651157702446298181724909751488398111196856600851670630078267092328086781153953555252419121204687358895149676397025159653789758530
var data = new Buffer(64);
data.fill(0);
var key = crypto.randomBytes(16);
var iv1 = new Buffer(16);
iv1.fill(255);
var iv2 = new Buffer('');
var cipher = crypto.createCipheriv('aes-128-ctr', key, iv1);
var decipher = crypto.createDecipheriv('aes-128-ecb', key, iv2);
var out = decipher.update(cipher.update(data));
console.log(out.toString('hex'));
function EVP_BytesToKey(password, len) {
var buff = md5(password);
var out = buff;
while (buff.length < len) {
buff = md5(buff + password);
out += buff;
}
return buff.slice(0, len);
}
function pbkdf2(password, salt, iterations, len, hashType) {
hashType = hashType || 'sha1';
if (!Buffer.isBuffer(password)) {
password = new Buffer(password);
}
if (!Buffer.isBuffer(salt)) {
salt = new Buffer(salt);
}
var out = new Buffer('');
var md, prev, i, j;
crypto.pbkdf2(password, salt, iterations, keylen, digest, function (err, key) {
// your key
});
crypto.subtle.importKey('raw', password, {name:'PBKDF2'}, false, ['deriveBits']).then(function (key) {
return crypto.subtle.deriveBits({
name: 'PBKDF2',
iterations: iterations,
salt: salt,
hash: 'SHA-1'
}, key, keylen);
}).then(function (result) {
// your key
});
// PouchDB 3.0.6
//
// (c) 2012-2014 Dale Harvey and the PouchDB team
// PouchDB may be freely distributed under the Apache license, version 2.0.
// For all details and documentation:
// http://pouchdb.com
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.PouchDB=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
var utils = _dereq_('./utils');
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<pre style="width: 100%; height: 100%;" id="output"></pre>
<script src="pouchdb.js"></script>
<script src="pouchdb.memory.js"></script>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<pre style="width: 100%; height: 100%;" id="output"></pre>
<script src="pouchdb.js"></script>
<script src="pouchdb.memory.js"></script>