work on archiver

This commit is contained in:
Dolan Miu
2016-03-31 18:03:16 +01:00
parent 5fa1c259d0
commit a88a59fd51
5 changed files with 59 additions and 9 deletions

View File

@ -0,0 +1,15 @@
import {Packer} from "./packer";
import * as fs from 'fs';
export class LocalPacker extends Packer {
private stream: fs.WriteStream
constructor(path: string) {
super();
this.stream = fs.createWriteStream(path);
}
pack() {
super.pack(this.stream);
}
}

View File

@ -1,5 +1,22 @@
import * as archiver from "archiver";
import {archiver, Zip} from "archiver";
import * as fs from 'fs';
export class Packer {
protected archive: Zip;
constructor() {
this.archive = archiver.create("fgf", {});
}
pack(output: fs.WriteStream): void {
this.archive.pipe(output);
this.archive.bulk([
{
expand: true,
cwd: __dirname + '/template',
src: ['**', '**/.rels']
}
]);
}
}

View File

@ -11,7 +11,7 @@ function jsonify(obj: Object) {
return JSON.parse(stringifiedJson);
}
describe.only('Formatter', () => {
describe('Formatter', () => {
var formatter: Formatter;
beforeEach(() => {

View File

@ -0,0 +1,19 @@
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import {LocalPacker} from "../export/packer/local";
import {assert} from "chai";
describe.only('Packer', () => {
var packer: LocalPacker;
beforeEach(() => {
packer = new LocalPacker("test.zip");
});
describe('#pack()', () => {
it("should create a standard docx file", () => {
packer.pack();
});
});
});

View File

@ -22,21 +22,20 @@ declare module "archiver" {
name?: string;
}
interface Archiver extends STREAM.Transform {
export interface Zip extends STREAM.Transform {
pipe(writeStream: FS.WriteStream): void;
append(readStream: FS.ReadStream, name: nameInterface): void;
finalize(): void;
bulk(mappings: any): void;
}
interface Options {
}
function archiver(format: string, options?: Options): Archiver;
function archiver(format: string, options?: Options): Zip;
namespace archiver {
function create(format: string, options?: Options): Archiver;
export namespace archiver {
function create(format: string, options?: Options): Zip;
}
export = archiver;
}