Skip to content

Commit

Permalink
removed fs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arshad Ali Abdul Samad authored and Arshad Ali Abdul Samad committed May 30, 2018
1 parent ebc81ee commit 685cd9b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 379 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,5 @@
"dependencies": {
"long": "^4.0.0",
"uuid-parse": "^1.0.0",
"winston": "^2.4.1"
}
}
45 changes: 6 additions & 39 deletions src/PSTFile/PSTFile.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import { PSTObject } from '../PSTObject/PSTObject.class';
import { PSTTableBC } from '../PSTTableBC/PSTTableBC.class';
import { PSTTableItem } from '../PSTTableItem/PSTTableItem.class';
import { PSTUtil } from '../PSTUtil/PSTUtil.class';
import * as fs from 'fs';
import * as util from 'util';
import * as long from 'long';
const uuidparse = require('uuid-parse');
Expand Down Expand Up @@ -97,20 +96,12 @@ export class PSTFile {
return this._pstFileType;
}

private _pstFilename: string = '';
public get pstFilename(): string {
return this._pstFilename;
}

// b-tree
private childrenDescriptorTree: Map<number, DescriptorIndexNode[]> | null = null;

// node tree maps
private static nodeMap: NodeMap = new NodeMap();

// file descriptor
private pstFD: number;

// in-memory file buffer (instead of filesystem)
private pstBuffer: Buffer = new Buffer(0);

Expand All @@ -119,21 +110,12 @@ export class PSTFile {

/**
* Creates an instance of PSTFile. File is opened in constructor.
* @param {string} fileName
* @param {Buffer} pstBuffer
* @memberof PSTFile
*/
public constructor(pstBuffer: Buffer);
public constructor(fileName: string);
public constructor(arg: any) {
if (arg instanceof Buffer) {
// use an in-memory buffer of PST
this.pstBuffer = arg;
this.pstFD = -1;
} else {
// use PST in filesystem
this._pstFilename = arg;
this.pstFD = fs.openSync(this._pstFilename, 'r');
}
// use an in-memory buffer of PST
this.pstBuffer = arg;

// confirm first 4 bytes are !BDN
let buffer = new Buffer(514);
Expand Down Expand Up @@ -166,16 +148,6 @@ export class PSTFile {
this.processNameToIDMap();
}

/**
* Close the file.
* @memberof PSTFile
*/
public close() {
if (this.pstFD > 0) {
fs.closeSync(this.pstFD);
}
}

/**
* Process name to ID map.
* @private
Expand Down Expand Up @@ -828,14 +800,9 @@ export class PSTFile {
* @memberof PSTFile
*/
private readSync(buffer: Buffer, length: number, position: number): number {
if (this.pstFD > 0) {
// read from file system
return fs.readSync(this.pstFD, buffer, 0, length, position);
} else {
// copy from in-memory buffer
this.pstBuffer.copy(buffer, 0, position, position + length);
return length;
}
// copy from in-memory buffer
this.pstBuffer.copy(buffer, 0, position, position + length);
return length;
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/PSTFile/PSTFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ const expect = chai.expect;
let pstFile: PSTFile;

before(() => {
pstFile = new PSTFile(resolve('./src/testdata/michelle_lokay_000_1_1_1_1.pst'));
});

after(() => {
pstFile.close();
pstFile = new PSTFile(fs.readFileSync('./src/testdata/michelle_lokay_000_1_1_1_1.pst'));
});

describe('PSTfile tests', () => {
it('should open the file', () => {
expect(pstFile.encryptionType).to.equal(1);
expect(pstFile.pstFileType).to.equal(23);
expect(pstFile.pstFilename).to.contain('michelle_lokay_000_1_1_1_1.pst');
expect(pstFile.getMessageStore().displayName).to.equal('Personal folders');
expect(pstFile.getRootFolder()).to.not.be.null;
});
Expand Down
64 changes: 0 additions & 64 deletions src/test-min.ts

This file was deleted.

Loading

0 comments on commit 685cd9b

Please sign in to comment.