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

[question] how to use this using typescript #47

Open
marpe opened this issue Jan 17, 2017 · 3 comments
Open

[question] how to use this using typescript #47

marpe opened this issue Jan 17, 2017 · 3 comments

Comments

@marpe
Copy link

marpe commented Jan 17, 2017

Hi,

I know this isn't really a question specifically for this lib, but can someone help me use this together with typescript? I tried specifying (in my tsconfig.json)
"paths": { "zlib_and_gzip": [ "node_modules/zlibjs/bin/zlib_and_gzip.min" ]
But I'm getting an error saying:
error TS2306: File 'node_modules/zlibjs/bin/zlib_and_gzip.min.js' is not a module.
Which isn't really a surprise... but is there a way to use it anyway?

If not, how would I got about packaging this using modules or can you suggest where to post this question?

Regards, Martin

@marpe
Copy link
Author

marpe commented Jan 18, 2017

Ah, I got it working using
"paths": { "zlibjs/bin/rawinflate.min.js": [ "node_modules/zlibjs/bin/rawinflate.min.js" ] }
and
import { Zlib } from 'zlibjs/bin/rawinflate.min.js';

Please close this :)

@equinox2k
Copy link

incase this helps anyone I created for zlib_and_gzip.min "zlibjs.d.ts" file...

declare module 'zlibjs/bin/zlib_and_gzip.min.js' {

    export namespace Zlib {

        enum CompressionType {
            NONE = 0,
            FIXED = 1,
            DYNAMIC = 2
        }

        export namespace Gzip {
            interface Options {
                deflateOptions: {
                    compressionType: Zlib.CompressionType
                },
                flags: {
                    fname: boolean, // use filename?
                    comment: boolean, // use comment?
                    fhcrc: boolean // use file checksum?
                },
                filename: string, // filename
                comment: string
            }
        }

        export namespace Deflate {
            interface Options {
                compressionType: CompressionType
            }
        }

        export namespace Inflate {
            enum BufferType {
                BLOCK = 0,
                ADAPTIVE = 1
            }
            interface Options {
                index: number, // start position in input buffer 
                bufferSize: number, // initial output buffer size
                bufferType: Zlib.Inflate.BufferType, // buffer expantion type
                resize: boolean, // resize buffer(ArrayBuffer) when end of decompression (default: false)
                verify: boolean  // verify decompression result (default: false)
            }
        }

        export class Gzip {
            constructor(data: Array<number>|Uint8Array, options: Gzip.Options);
            public compress() : Uint8Array;
        }

        export class Gunzip {
            constructor(data: Array<number>|Uint8Array);
            public decompress() : Uint8Array;
        }

        export class Deflate {
            constructor(data: Array<number>|Uint8Array, options: Deflate.Options);
            public compress() : Uint8Array;
        }

        export class Inflate {
            constructor(data: Array<number>|Uint8Array, options: Inflate.Options);
            public decompress() : Uint8Array;
        }

    }

}

@ssjzhong
Copy link

@equinox2k Thank you, maybe you can try to create a pull request for this definition to DefinitelyTyped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants