mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Untar operation now uses lib/Stream library
This commit is contained in:
parent
fd07b89028
commit
3ae225ac59
2 changed files with 3 additions and 34 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
|
import Stream from "../lib/Stream";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Untar operation
|
* Untar operation
|
||||||
|
@ -41,38 +42,6 @@ class Untar extends Operation {
|
||||||
* @returns {List<File>}
|
* @returns {List<File>}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const Stream = function(input) {
|
|
||||||
this.bytes = input;
|
|
||||||
this.position = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
Stream.prototype.getBytes = function(bytesToGet) {
|
|
||||||
const newPosition = this.position + bytesToGet;
|
|
||||||
const bytes = this.bytes.slice(this.position, newPosition);
|
|
||||||
this.position = newPosition;
|
|
||||||
return bytes;
|
|
||||||
};
|
|
||||||
|
|
||||||
Stream.prototype.readString = function(numBytes) {
|
|
||||||
let result = "";
|
|
||||||
for (let i = this.position; i < this.position + numBytes; i++) {
|
|
||||||
const currentByte = this.bytes[i];
|
|
||||||
if (currentByte === 0) break;
|
|
||||||
result += String.fromCharCode(currentByte);
|
|
||||||
}
|
|
||||||
this.position += numBytes;
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
Stream.prototype.readInt = function(numBytes, base) {
|
|
||||||
const string = this.readString(numBytes);
|
|
||||||
return parseInt(string, base);
|
|
||||||
};
|
|
||||||
|
|
||||||
Stream.prototype.hasMore = function() {
|
|
||||||
return this.position < this.bytes.length;
|
|
||||||
};
|
|
||||||
|
|
||||||
const stream = new Stream(input),
|
const stream = new Stream(input),
|
||||||
files = [];
|
files = [];
|
||||||
|
|
||||||
|
@ -85,7 +54,7 @@ class Untar extends Operation {
|
||||||
ownerUID: stream.readString(8),
|
ownerUID: stream.readString(8),
|
||||||
ownerGID: stream.readString(8),
|
ownerGID: stream.readString(8),
|
||||||
size: parseInt(stream.readString(12), 8), // Octal
|
size: parseInt(stream.readString(12), 8), // Octal
|
||||||
lastModTime: new Date(1000 * stream.readInt(12, 8)), // Octal
|
lastModTime: new Date(1000 * parseInt(stream.readString(12), 8)), // Octal
|
||||||
checksum: stream.readString(8),
|
checksum: stream.readString(8),
|
||||||
type: stream.readString(1),
|
type: stream.readString(1),
|
||||||
linkedFileName: stream.readString(100),
|
linkedFileName: stream.readString(100),
|
||||||
|
|
|
@ -87,7 +87,7 @@ module.exports = {
|
||||||
// Check output
|
// Check output
|
||||||
browser
|
browser
|
||||||
.useCss()
|
.useCss()
|
||||||
.waitForElementNotVisible("#stale-indicator", 500)
|
.waitForElementNotVisible("#stale-indicator", 1000)
|
||||||
.expect.element("#output-text").to.have.value.that.equals("44 6f 6e 27 74 20 50 61 6e 69 63 2e");
|
.expect.element("#output-text").to.have.value.that.equals("44 6f 6e 27 74 20 50 61 6e 69 63 2e");
|
||||||
|
|
||||||
// Clear recipe
|
// Clear recipe
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue