Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "uue", | ||
"main": "uue.js", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "UUE decoder and encoder for Node.js", | ||
@@ -11,3 +11,7 @@ "keywords": ["UUE", "uuencode", "uudecode", "uuencoding", "uudecoding"], | ||
"url": "https://github.com/Mithgol/node-uue.git" | ||
}, | ||
"scripts": { | ||
"pretest": "jshint uue.js test/", | ||
"test": "mocha --reporter spec --timeout 60s" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
The **UUE** module is able to decode [uuencoded](http://en.wikipedia.org/wiki/Uuencoding) files from a text message. | ||
The **UUE** module is able to perform [uuencoding](http://en.wikipedia.org/wiki/Uuencoding) of a file (or Node.js Buffer) to a text message. | ||
@@ -7,4 +7,54 @@ The module is named after a common `.UUE` suffix for Fidonet echomail areas spreading uuencoded files (sometimes the results of such encoding are also known as “UUE codes”). | ||
## Installing the UUE module | ||
[![(npm package version)](https://nodei.co/npm/uue.png?downloads=true)](https://npmjs.org/package/uue) | ||
* Latest packaged version: `npm install uue` | ||
* Latest githubbed version: `npm install https://github.com/Mithgol/node-uue/tarball/master` | ||
The npm package does not contain the tests, they're published on GitHub only. | ||
You may visit https://github.com/Mithgol/node-uue#readme occasionally to read the latest `README` because the package's version is not planned to grow after changes when they happen in `README` only. (And `npm publish --force` is [forbidden](http://blog.npmjs.org/post/77758351673/no-more-npm-publish-f) nowadays.) | ||
## Using the UUE module | ||
When you `require()` the installed module, you get an object that has the following method: | ||
### encode(encodeSource, encodeOptions) | ||
Returns a string of UUE codes that represent the given source. | ||
* If `encodeSource` is a string, it is interpreted as a path of some file, and that file is uuencoded. | ||
* If `encodeSource` is a Node.js [Buffer](http://nodejs.org/docs/latest/api/buffer.html), the contents of that buffer become uuencoded. | ||
The optional `encodeOptions` parameter is an object with the following optional properties: | ||
* `mode` — read/write/execute permissions for the file. If this property is omitted, three last octal digits of the `mode` property of the given file's [`fs.Stats`](http://nodejs.org/docs/latest/api/fs.html#fs_class_fs_stats) object are used (or `'644'` if a Buffer is given in `encodeSource` instead of a file). The `mode` property may be given as a string (of octal digits) or as a number (for example, `'666'` and `438` are equivalent). | ||
* `filename` — a file's name to be given in UUE codes. (For example, if `encodeOptions` is `{mode:'664', filename:'filename.ext'}`, then the first line of UUE codes is `begin 664 filename.ext`.) If this property is omitted, then [`path.basename(encodeSource)`](http://nodejs.org/docs/latest/api/path.html#path_path_basename_p_ext) is used (or `'buffer.bin'` if a Buffer is given in `encodeSource` instead of a file). | ||
* `eol` — end-of-line character(s). If this property is omitted, `\n` (`\x0A`) is used (as in Web or UN*X applications). You may want to set `encodeOptions.eol` equal to [`os.EOL`](http://nodejs.org/docs/latest/api/os.html#os_os_eol) on other systems. The value of `encodeOptions.eol` is used only as a separator between lines of UUE codes, but neither in the beginning nor at the end of the returned string. | ||
## Locking files | ||
The module **does not** lock any files and **does not** create any “lock files” (flag files, semaphore files). The module's caller should control the access to the file being encoded. | ||
## Testing the UUE module | ||
[![(build testing status)](https://travis-ci.org/Mithgol/node-uue.svg?branch=master)](https://travis-ci.org/Mithgol/node-uue) | ||
The tests are not included in the npm package of the module (to keep it small). Use the version from GitHub. | ||
It is necessary to install [Mocha](http://visionmedia.github.io/mocha/) and [JSHint](http://jshint.com/) for testing. | ||
* You may install Mocha globally (`npm install mocha -g`) or locally (`npm install mocha` in the directory of the UUE module). | ||
* You may install JSHint globally (`npm install jshint -g`) or locally (`npm install jshint` in the directory of the UUE module). | ||
After that you may run `npm test` (in the directory of the UUE module). | ||
## License | ||
MIT license (see the `LICENSE` file). |
158
uue.js
@@ -1,1 +0,157 @@ | ||
console.log('Hello, UUE.'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var UUE = function(){ | ||
if (!(this instanceof UUE)) return new UUE(); | ||
}; | ||
UUE.prototype.encode = function(encodeSource, encodeOptions){ | ||
/* jshint bitwise:false */ | ||
if( typeof encodeOptions === 'undefined' ) encodeOptions = {}; | ||
if( typeof encodeSource === 'string' ){ // treat as filename | ||
// check encodeOptions.mode | ||
if( typeof encodeOptions.mode === 'undefined' ){ | ||
encodeOptions.mode = ( | ||
fs.statSync(encodeSource).mode & parseInt('777', 8) | ||
).toString(8); | ||
} else if( typeof encodeOptions.mode !== 'string' ){ | ||
encodeOptions.mode = encodeOptions.mode.toString(8); | ||
} | ||
// check encodeOptions.filename | ||
if( typeof encodeOptions.filename === 'undefined' ){ | ||
encodeOptions.filename = path.basename(encodeSource); | ||
} | ||
// make encodeSource a buffer | ||
encodeSource = fs.readFileSync(encodeSource); | ||
} else if( Buffer.isBuffer(encodeSource) ){ // treat as buffer | ||
// check encodeOptions.mode | ||
if( typeof encodeOptions.mode === 'undefined' ){ | ||
encodeOptions.mode = '644'; | ||
} else if( typeof encodeOptions.mode !== 'string' ){ | ||
encodeOptions.mode = encodeOptions.mode.toString(8); | ||
} | ||
// check encodeOptions.filename | ||
if( typeof encodeOptions.filename === 'undefined' ){ | ||
encodeOptions.filename = 'buffer.bin'; | ||
} | ||
} else throw new Error(this.errors.UNKNOWN_SOURCE_TYPE); | ||
if( typeof encodeOptions.eol === 'undefined' ) encodeOptions.eol = '\n'; | ||
// now encodeSource is always a buffer | ||
var output = []; | ||
output.push('begin '); | ||
output.push(encodeOptions.mode); | ||
output.push(' '); | ||
output.push(encodeOptions.filename); | ||
output.push(encodeOptions.eol); | ||
var offset = 0; | ||
while( offset < encodeSource.length ){ | ||
var triplet, byte1, byte2, byte3, total, charCode; | ||
if( encodeSource.length - offset >= 45 ){ // complete line, 15 triplets | ||
output.push(String.fromCharCode(45 + 32)); | ||
for( triplet = 0; triplet < 15; triplet++ ){ | ||
byte1 = encodeSource.readUInt8(offset); | ||
offset++; | ||
byte2 = encodeSource.readUInt8(offset); | ||
offset++; | ||
byte3 = encodeSource.readUInt8(offset); | ||
offset++; | ||
total = (byte1 << 16) + (byte2 << 8) + byte3; | ||
charCode = total >>> 18; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
charCode = (total >>> 12) & 0x3F; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
charCode = (total >>> 6) & 0x3F; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
charCode = total & 0x3F; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
} | ||
} else { // last line, less than 15 triplets | ||
output.push(String.fromCharCode(encodeSource.length - offset + 32)); | ||
var tripletNum = ( (encodeSource.length - offset) /3 ) |0; | ||
for( triplet = 0; triplet < tripletNum; triplet++ ){ | ||
byte1 = encodeSource.readUInt8(offset); | ||
offset++; | ||
byte2 = encodeSource.readUInt8(offset); | ||
offset++; | ||
byte3 = encodeSource.readUInt8(offset); | ||
offset++; | ||
total = (byte1 << 16) + (byte2 << 8) + byte3; | ||
charCode = total >>> 18; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
charCode = (total >>> 12) & 0x3F; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
charCode = (total >>> 6) & 0x3F; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
charCode = total & 0x3F; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
} | ||
if( offset < encodeSource.length ){ // some bytes remain | ||
byte1 = encodeSource.readUInt8(offset); | ||
offset++; | ||
if( offset < encodeSource.length ){ | ||
byte2 = encodeSource.readUInt8(offset); | ||
offset++; | ||
} else byte2 = 0; | ||
if( offset < encodeSource.length ){ | ||
byte3 = encodeSource.readUInt8(offset); | ||
offset++; | ||
} else byte3 = 0; | ||
total = (byte1 << 16) + (byte2 << 8) + byte3; | ||
charCode = total >>> 18; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
charCode = (total >>> 12) & 0x3F; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
charCode = (total >>> 6) & 0x3F; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
charCode = total & 0x3F; | ||
if( charCode === 0 ) charCode = 64; | ||
output.push(String.fromCharCode(charCode + 32)); | ||
} | ||
} | ||
output.push(encodeOptions.eol); | ||
} | ||
output.push('`'); | ||
output.push(encodeOptions.eol); | ||
output.push('end'); | ||
return output.join(''); | ||
}; | ||
UUE.prototype.errors = { | ||
UNKNOWN_SOURCE_TYPE: "The source's type is unknown!" | ||
}; | ||
module.exports = new UUE(); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
12150
7
129
59
0
1