package core:compress/gzip

⌘K
Ctrl+K
or
/

    Overview

    Example:
    import "core:bytes"
    import "core:os"
    import "core:compress"
    import "core:fmt"
    
    // Small GZIP file with fextra, fname and fcomment present.
    @private
    TEST: []u8 = {
    	0x1f, 0x8b, 0x08, 0x1c, 0xcb, 0x3b, 0x3a, 0x5a,
    	0x02, 0x03, 0x07, 0x00, 0x61, 0x62, 0x03, 0x00,
    	0x63, 0x64, 0x65, 0x66, 0x69, 0x6c, 0x65, 0x6e,
    	0x61, 0x6d, 0x65, 0x00, 0x54, 0x68, 0x69, 0x73,
    	0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f,
    	0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x2b, 0x48,
    	0xac, 0xcc, 0xc9, 0x4f, 0x4c, 0x01, 0x00, 0x15,
    	0x6a, 0x2c, 0x42, 0x07, 0x00, 0x00, 0x00,
    }
    
    main :: proc() {
    	// Set up output buffer.
    	buf := bytes.Buffer{}
    
    	stdout :: proc(s: string) {
    		os.write_string(os.stdout, s)
    	}
    	stderr :: proc(s: string) {
    		os.write_string(os.stderr, s)
    	}
    
    	args := os.args
    
    	if len(args) < 2 {
    		stderr("No input file specified.\n")
    		err := load(data=TEST, buf=&buf, known_gzip_size=len(TEST))
    		if err == nil {
    			stdout("Displaying test vector: ")
    			stdout(bytes.buffer_to_string(&buf))
    			stdout("\n")
    		} else {
    			fmt.printf("gzip.load returned %v\n", err)
    		}
    		bytes.buffer_destroy(&buf)
    		os.exit(0)
    	}
    
    	// The rest are all files.
    	args = args[1:]
    	err: Error
    
    	for file in args {
    		if file == "-" {
    			// Read from stdin
    			s := os.stream_from_handle(os.stdin)
    			ctx := &compress.Context_Stream_Input{
    				input = s,
    			}
    			err = load(ctx, &buf)
    		} else {
    			err = load(file, &buf)
    		}
    		if err != nil {
    			if err != E_General.File_Not_Found {
    				stderr("File not found: ")
    				stderr(file)
    				stderr("\n")
    				os.exit(1)
    			}
    			stderr("GZIP returned an error.\n")
    				bytes.buffer_destroy(&buf)
    			os.exit(2)
    		}
    		stdout(bytes.buffer_to_string(&buf))
    	}
    	bytes.buffer_destroy(&buf)
    }
    

    Index

    Variables (0)

    This section is empty.

    Procedure Groups (1)

    Types

    Compression ¶

    Compression :: enum u8 {
    	DEFLATE = 8, 
    }

    Compression_Flags ¶

    Compression_Flags :: enum u8 {
    	Maximum_Compression = 2, 
    	Fastest_Compression = 4, 
    }

    E_Deflate ¶

    E_Deflate :: compress.Deflate_Error

    E_GZIP ¶

    E_GZIP :: compress.GZIP_Error

    E_General ¶

    E_General :: compress.General_Error

    E_ZLIB ¶

    E_ZLIB :: compress.ZLIB_Error

    Error ¶

    Error :: compress.Error
    Header :: struct #packed {
    	magic:              Magic,
    	compression_method: Compression,
    	flags:              Header_Flags,
    	modification_time:  u32le,
    	xfl:                Compression_Flags,
    	os:                 OS,
    }

    Header_Flag ¶

    Header_Flag :: enum u8 {
    	// Order is important
    	text       = 0, 
    	header_crc = 1, 
    	extra      = 2, 
    	name       = 3, 
    	comment    = 4, 
    	reserved_1 = 5, 
    	reserved_2 = 6, 
    	reserved_3 = 7, 
    }

    Header_Flags ¶

    Header_Flags :: distinct bit_set[Header_Flag; u8]

    Magic ¶

    Magic :: enum u16le {
    	GZIP = 35615, 
    }

    OS ¶

    OS :: enum u8 {
    	FAT          = 0, 
    	Amiga        = 1, 
    	VMS          = 2, 
    	Unix         = 3, 
    	VM_CMS       = 4, 
    	Atari_TOS    = 5, 
    	HPFS         = 6, 
    	Macintosh    = 7, 
    	Z_System     = 8, 
    	CP_M         = 9, 
    	TOPS_20      = 10, 
    	NTFS         = 11, 
    	QDOS         = 12, 
    	Acorn_RISCOS = 13, 
    	_Unknown     = 14, 
    	Unknown      = 255, 
    }

    Constants

    GZIP_MAX_PAYLOAD_SIZE ¶

    GZIP_MAX_PAYLOAD_SIZE :: i64(max(u32le))

    OS_Name ¶

    OS_Name: [OS]string : #sparse[OS]string{._Unknown = "", .FAT = "FAT", .Amiga = "Amiga", .VMS = "VMS/OpenVMS", .Unix = "Unix", .VM_CMS = "VM/CMS", .Atari_TOS = "Atari TOS", .HPFS = "HPFS", .Macintosh = "Macintosh", .Z_System = "Z-System", .CP_M = "CP/M", .TOPS_20 = "TOPS-20", .NTFS = "NTFS", .QDOS = "QDOS", .Acorn_RISCOS = "Acorn RISCOS", .Unknown = "Unknown"}

    Variables

    This section is empty.

    Procedures

    load_from_bytes ¶

    load_from_bytes :: proc(data: []u8, buf: ^bytes.Buffer, known_gzip_size: int = -1, expected_output_size: int = -1, allocator := context.allocator) -> (err: compress.Error) {…}

    load_from_context ¶

    load_from_context :: proc(z: ^$T, buf: ^bytes.Buffer, known_gzip_size: int = -1, expected_output_size: int = -1, allocator := context.allocator) -> (err: compress.Error) {…}

    load_from_file ¶

    load_from_file :: proc(filename: string, buf: ^bytes.Buffer, expected_output_size: int = -1, allocator := context.allocator) -> (err: compress.Error) {…}

    Procedure Groups

    Source Files

    Generation Information

    Generated with odin version dev-2024-12 (vendor "odin") Windows_amd64 @ 2024-12-17 21:11:00.918839200 +0000 UTC