pax_global_header00006660000000000000000000000064134727427540014531gustar00rootroot0000000000000052 comment=af13114809291393846a56eddbb1ac2035ae397c base64id-2.0.0/000077500000000000000000000000001347274275400131315ustar00rootroot00000000000000base64id-2.0.0/.gitignore000066400000000000000000000001251347274275400151170ustar00rootroot00000000000000.DS_Store lib-cov *.seed *.log *.csv *.dat *.out *.pid benchmarks/*.png node_modules base64id-2.0.0/.npmignore000066400000000000000000000000261347274275400151260ustar00rootroot00000000000000support test examples base64id-2.0.0/CHANGELOG.md000066400000000000000000000006761347274275400147530ustar00rootroot00000000000000# [2.0.0](https://github.com/faeldt/base64id/compare/1.0.0...2.0.0) (2019-05-27) ### Code Refactoring * **buffer:** replace deprecated Buffer constructor usage ([#11](https://github.com/faeldt/base64id/issues/11)) ([ccfba54](https://github.com/faeldt/base64id/commit/ccfba54)) ### BREAKING CHANGES * **buffer:** drop support for Node.js ≤ 4.4.x and 5.0.0 - 5.9.x See: https://nodejs.org/en/docs/guides/buffer-constructor-deprecation/ base64id-2.0.0/LICENSE000066400000000000000000000021361347274275400141400ustar00rootroot00000000000000(The MIT License) Copyright (c) 2012-2016 Kristian Faeldt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. base64id-2.0.0/README.md000066400000000000000000000006211347274275400144070ustar00rootroot00000000000000base64id ======== Node.js module that generates a base64 id. Uses crypto.randomBytes when available, falls back to unsafe methods for node.js <= 0.4. To increase performance, random bytes are buffered to minimize the number of synchronous calls to crypto.randomBytes. ## Installation $ npm install base64id ## Usage var base64id = require('base64id'); var id = base64id.generateId(); base64id-2.0.0/lib/000077500000000000000000000000001347274275400136775ustar00rootroot00000000000000base64id-2.0.0/lib/base64id.js000066400000000000000000000044751347274275400156500ustar00rootroot00000000000000/*! * base64id v0.1.0 */ /** * Module dependencies */ var crypto = require('crypto'); /** * Constructor */ var Base64Id = function() { }; /** * Get random bytes * * Uses a buffer if available, falls back to crypto.randomBytes */ Base64Id.prototype.getRandomBytes = function(bytes) { var BUFFER_SIZE = 4096 var self = this; bytes = bytes || 12; if (bytes > BUFFER_SIZE) { return crypto.randomBytes(bytes); } var bytesInBuffer = parseInt(BUFFER_SIZE/bytes); var threshold = parseInt(bytesInBuffer*0.85); if (!threshold) { return crypto.randomBytes(bytes); } if (this.bytesBufferIndex == null) { this.bytesBufferIndex = -1; } if (this.bytesBufferIndex == bytesInBuffer) { this.bytesBuffer = null; this.bytesBufferIndex = -1; } // No buffered bytes available or index above threshold if (this.bytesBufferIndex == -1 || this.bytesBufferIndex > threshold) { if (!this.isGeneratingBytes) { this.isGeneratingBytes = true; crypto.randomBytes(BUFFER_SIZE, function(err, bytes) { self.bytesBuffer = bytes; self.bytesBufferIndex = 0; self.isGeneratingBytes = false; }); } // Fall back to sync call when no buffered bytes are available if (this.bytesBufferIndex == -1) { return crypto.randomBytes(bytes); } } var result = this.bytesBuffer.slice(bytes*this.bytesBufferIndex, bytes*(this.bytesBufferIndex+1)); this.bytesBufferIndex++; return result; } /** * Generates a base64 id * * (Original version from socket.io ) */ Base64Id.prototype.generateId = function () { var rand = Buffer.alloc(15); // multiple of 3 for base64 if (!rand.writeInt32BE) { return Math.abs(Math.random() * Math.random() * Date.now() | 0).toString() + Math.abs(Math.random() * Math.random() * Date.now() | 0).toString(); } this.sequenceNumber = (this.sequenceNumber + 1) | 0; rand.writeInt32BE(this.sequenceNumber, 11); if (crypto.randomBytes) { this.getRandomBytes(12).copy(rand); } else { // not secure for node 0.4 [0, 4, 8].forEach(function(i) { rand.writeInt32BE(Math.random() * Math.pow(2, 32) | 0, i); }); } return rand.toString('base64').replace(/\//g, '_').replace(/\+/g, '-'); }; /** * Export */ exports = module.exports = new Base64Id(); base64id-2.0.0/package.json000066400000000000000000000005521347274275400154210ustar00rootroot00000000000000{ "name": "base64id" , "version": "2.0.0" , "license": "MIT" , "description": "Generates a base64 id" , "author": "Kristian Faeldt " , "repository": { "type": "git" , "url": "https://github.com/faeldt/base64id.git" } , "main": "./lib/base64id.js" , "engines": { "node": "^4.5.0 || >= 5.9" } }