Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decaf src #6

Open
wants to merge 20 commits into
base: machine-decaf-source
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions Gruntfile.coffee

This file was deleted.

2 changes: 1 addition & 1 deletion bin/scandal
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require("../lib/scandal.js").main();
require("../src/scandal.js").main();
12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
"name": "scandal",
"version": "3.2.0",
"description": "Directory Search and Scan Utilities",
"main": "./lib/scandal.js",
"main": "./src/scandal.js",
"bin": {
"scandal": "./bin/scandal"
},
"scripts": {
"test": "grunt test",
"prepublish": "grunt clean lint coffee"
"test": "jasmine-focused --captureExceptions --coffee spec/"
},
"repository": {
"type": "git",
Expand All @@ -28,14 +27,7 @@
"temp": "^0.8.3"
},
"devDependencies": {
"coffeelint": "^1.15.7",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-coffeelint": "0.0.13",
"grunt-contrib-coffee": "^0.13.0",
"grunt-shell": "^1.1.2",
"jasmine-focused": "^1.0.7",
"rimraf": "^2.4.2",
"wrench": "^1.5.8"
}
}
12 changes: 2 additions & 10 deletions src/chunked-executor.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS202: Simplify dynamic range loops
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
let ChunkedExecutor;
const MAX_CONCURRENT_CHUNK = 20;

// Public: {ChunkedExecutor} will execute on an {Array} paths in a pathQueue only
Expand All @@ -27,7 +19,7 @@ const MAX_CONCURRENT_CHUNK = 20;
// executor.push '/path/to/lastone.coffee'
// ```
module.exports =
(ChunkedExecutor = class ChunkedExecutor {
class ChunkedExecutor {

// Construct a {ChunkedExecutor}
//
Expand Down Expand Up @@ -93,4 +85,4 @@ module.exports =
this.executeNextPathIfPossible();
if (this.pathCount === 0) { return this.doneCallback(); }
}
});
}
146 changes: 64 additions & 82 deletions src/chunked-line-reader.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/*
* decaffeinate suggestions:
* DS002: Fix invalid constructor
* DS102: Remove unnecessary code created because of implicit returns
* DS206: Consider reworking classes to avoid initClass
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
let ChunkedLineReader;
const fs = require("fs");
const isBinaryFile = require("isbinaryfile");
const {Readable} = require('stream');
Expand All @@ -32,88 +23,79 @@ const lastIndexOf = function(buffer, length, char) {
// This will collect all the lines in the file, or you can process each line in
// the data handler for more efficiency.
module.exports =
(ChunkedLineReader = (function() {
ChunkedLineReader = class ChunkedLineReader extends Readable {
static initClass() {
class ChunkedLineReader extends Readable {
constructor(filePath, options) {
super();
this.encoding = options?.encoding ?? "utf8";
this.filePath = filePath;

this.CHUNK_SIZE = 10240;
this.chunkedBuffer = null;
this.headerBuffer = new Buffer(256);
}

constructor(filePath, options) {
this.encoding = (options != null ? options.encoding : undefined) != null ? (options != null ? options.encoding : undefined) : "utf8";
super();
this.filePath = filePath;
}

isBinaryFile() {
const fd = fs.openSync(this.filePath, "r");
const isBin = isBinaryFile(this.constructor.headerBuffer, fs.readSync(fd, this.constructor.headerBuffer, 0, 256));
fs.closeSync(fd);
return isBin;
}

_read() {
let fd;
try {
fd = fs.openSync(this.filePath, "r");
const line = 0;
let offset = 0;
let remainder = '';
const chunkSize = this.constructor.CHUNK_SIZE;
if (isBinaryFile(this.constructor.headerBuffer, fs.readSync(fd, this.constructor.headerBuffer, 0, 256))) { return; }
this.CHUNK_SIZE = 10240;
this.chunkedBuffer = null;
this.headerBuffer = new Buffer(256);
}

if (this.constructor.chunkedBuffer == null) { this.constructor.chunkedBuffer = new Buffer(chunkSize); }
const {
chunkedBuffer
} = this.constructor;
let bytesRead = fs.readSync(fd, chunkedBuffer, 0, chunkSize, 0);
const decoder = new StringDecoder(this.encoding);
isBinaryFile() {
const fd = fs.openSync(this.filePath, "r");
const isBin = isBinaryFile(this.headerBuffer, fs.readSync(fd, this.headerBuffer, 0, 256));
fs.closeSync(fd);
return isBin;
}

while (bytesRead) {
// Scary looking. Uses very few new objects
var newRemainder, str;
const char = 10;
const index = lastIndexOf(chunkedBuffer, bytesRead, char);
_read() {
let fd;
try {
fd = fs.openSync(this.filePath, "r");
const line = 0;
let offset = 0;
let remainder = '';
const chunkSize = this.CHUNK_SIZE;
if (isBinaryFile(this.headerBuffer, fs.readSync(fd, this.headerBuffer, 0, 256))) { return; }

if (index < 0) {
// no newlines here, the whole thing is a remainder
newRemainder = decoder.write(chunkedBuffer.slice(0, bytesRead));
str = null;
} else if ((index > -1) && (index === (bytesRead - 1))) {
// the last char is a newline
newRemainder = '';
str = decoder.write(chunkedBuffer.slice(0, bytesRead));
} else {
str = decoder.write(chunkedBuffer.slice(0, index+1));
newRemainder = decoder.write(chunkedBuffer.slice(index+1, bytesRead));
}
if (this.chunkedBuffer == null) { this.chunkedBuffer = new Buffer(chunkSize); }
const chunkedBuffer = this.chunkedBuffer;
let bytesRead = fs.readSync(fd, chunkedBuffer, 0, chunkSize, 0);
const decoder = new StringDecoder(this.encoding);

if (str) {
if (remainder) { str = remainder + str; }
this.push(str);
remainder = newRemainder;
} else {
remainder = remainder + newRemainder;
}
while (bytesRead) {
// Scary looking. Uses very few new objects
var newRemainder, str;
const char = 10;
const index = lastIndexOf(chunkedBuffer, bytesRead, char);

offset += bytesRead;
bytesRead = fs.readSync(fd, chunkedBuffer, 0, chunkSize, offset);
if (index < 0) {
// no newlines here, the whole thing is a remainder
newRemainder = decoder.write(chunkedBuffer.slice(0, bytesRead));
str = null;
} else if ((index > -1) && (index === (bytesRead - 1))) {
// the last char is a newline
newRemainder = '';
str = decoder.write(chunkedBuffer.slice(0, bytesRead));
} else {
str = decoder.write(chunkedBuffer.slice(0, index+1));
newRemainder = decoder.write(chunkedBuffer.slice(index+1, bytesRead));
}

if (remainder) { return this.push(remainder); }
if (str) {
if (remainder) { str = remainder + str; }
this.push(str);
remainder = newRemainder;
} else {
remainder = remainder + newRemainder;
}

} catch (error) {
return this.emit('error', error);
offset += bytesRead;
bytesRead = fs.readSync(fd, chunkedBuffer, 0, chunkSize, offset);
}

finally {
if (fd != null) { fs.closeSync(fd); }
this.push(null);
}
if (remainder) { return this.push(remainder); }

} catch (error) {
return this.emit('error', error);
}
};
ChunkedLineReader.initClass();
return ChunkedLineReader;
})());

finally {
if (fd != null) { fs.closeSync(fd); }
this.push(null);
}
}
}
13 changes: 3 additions & 10 deletions src/chunked-scanner.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
/*
* decaffeinate suggestions:
* DS002: Fix invalid constructor
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
let ChunkedScanner;
const ChunkedExecutor = require('./chunked-executor');

module.exports =
(ChunkedScanner = class ChunkedScanner extends ChunkedExecutor {
class ChunkedScanner extends ChunkedExecutor {
constructor(scanner, execPathFn) {
this.finishedScanning = false;
super([], execPathFn);
this.finishedScanning = false;
this.onFinishedScanning = this.onFinishedScanning.bind(this);
this.scanner = scanner;
}
Expand Down Expand Up @@ -40,4 +33,4 @@ module.exports =

return isFinished;
}
});
}
Loading
Loading