Skip to content

Commit

Permalink
test: More ignores.
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed May 8, 2019
1 parent 5b52419 commit 6811fff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/io/event-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function readableStream<T>(func: (stream: any, i: number) => Promise<T |

function get(err?: Error, data: T | null = null) {

/* istanbul ignore if */
if (err) {
stream.emit('error', err);
if (!continueOnError) {
Expand Down
18 changes: 14 additions & 4 deletions lib/io/ole-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class Header {
public static load(buffer: Buffer): Header {
const header = new Header();
for (let i = 0; i < 8; i++) {
/* istanbul ignore if */
if (header.oleId[i] !== buffer[i]) {
throw new Error(`Doesn't look like a valid compound document (wrong ID, 0x${header.oleId[i].toString(16)} must be equal to 0x${buffer[i].toString(16)}).`);
}
Expand Down Expand Up @@ -238,6 +239,7 @@ export class Storage {
}

public storage(storageName: string): Storage {
/* istanbul ignore if */
if (!this.dirEntry.storages[storageName]) {
throw new Error(`No such storage "${storageName}".`);
}
Expand Down Expand Up @@ -282,6 +284,7 @@ export class Storage {
offset = 0;
return buffer;

/* istanbul ignore next */
} catch (err) {
stream.emit('error', err);
stream.emit('end');
Expand Down Expand Up @@ -318,6 +321,7 @@ export class Storage {
*/
public async streamFiltered<T>(streamName: string, offset: number, next: (data: ReadResult) => Promise<number | null>): Promise<void> {
const streamEntry = this.dirEntry.streams[streamName];
/* istanbul ignore if */
if (!streamEntry) {
throw new Error('No such stream "' + streamName + '" in document.');
}
Expand Down Expand Up @@ -366,6 +370,7 @@ export class Storage {
// read missing sectors
const remainingLen = -len - resultBuffer.length;
const numSecs = Math.ceil(remainingLen / secSize);
/* istanbul ignore if */
if (remainingLen > bytes - storageOffset) {
throw new Error(`Cannot read ${remainingLen} bytes when only ${bytes - storageOffset} remain in stream.`);
}
Expand Down Expand Up @@ -407,6 +412,7 @@ export class Storage {
return new Promise<Buffer>((resolve, reject) => {
const strm = this.stream(key, offset, bytesToRead);
const bufs: Buffer[] = [];
/* istanbul ignore if */
if (!strm) {
return reject(new Error('No such stream "' + key + '".'));
}
Expand Down Expand Up @@ -455,6 +461,7 @@ export class OleCompoundDoc extends EventEmitter {
return doc;
}

/* istanbul ignore next: Don't currently need this (at all) */
public async readWithCustomHeader(size: number): Promise<Buffer> {
this.skipBytes = size;
await this.openFile();
Expand All @@ -477,10 +484,10 @@ export class OleCompoundDoc extends EventEmitter {
return this.rootStorage.storage(storageName);
}

public stream(streamName: string, offset: number = 0, len: number = -1) {
this.assertLoaded();
return this.rootStorage.stream(streamName, offset, len);
}
// public stream(streamName: string, offset: number = 0, len: number = -1) {
// this.assertLoaded();
// return this.rootStorage.stream(streamName, offset, len);
// }

public async readSector(secId: number, offset: number = 0, bytesToRead: number = 0) {
this.assertLoaded();
Expand Down Expand Up @@ -553,6 +560,7 @@ export class OleCompoundDoc extends EventEmitter {
}

private assertLoaded() {
/* istanbul ignore if */
if (!this.fd) {
throw new Error('Document must be loaded first.');
}
Expand Down Expand Up @@ -615,6 +623,7 @@ export class OleCompoundDoc extends EventEmitter {

private async readSSAT(): Promise<void> {
const secIds = this.SAT.getSecIdChain(this.header.SSATSecId);
/* istanbul ignore if */
if (secIds.length !== this.header.SSATSize) {
throw new Error('Invalid Short Sector Allocation Table');
}
Expand Down Expand Up @@ -649,6 +658,7 @@ export class OleCompoundDoc extends EventEmitter {
private async read(buffer: Buffer, offset: number, length: number, position: number): Promise<[ number, Buffer ]> {
return new Promise((resolve, reject) => {
read(this.fd, buffer, offset, length, position, (err, bytesRead, data) => {
/* istanbul ignore if */
if (err) {
reject(err);
return;
Expand Down

0 comments on commit 6811fff

Please sign in to comment.