hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

types.ha (1254B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use io;
      5 
      6 // The size of each block in a tar file.
      7 export def BLOCKSZ: size = 512;
      8 
      9 // A file or directory in a tar file.
     10 export type entry = struct {
     11 	ent_reader,
     12 	name: str,
     13 	mode: uint,
     14 	uid: uint,
     15 	gid: uint,
     16 	fsize: size,
     17 	mtime: uint,
     18 	checksum: uint,
     19 	etype: entry_type,
     20 	link: str,
     21 	uname: str,
     22 	gname: str,
     23 	devmajor: u64,
     24 	devminor: u64,
     25 };
     26 
     27 export type ent_reader = struct {
     28 	vtable: io::stream,
     29 	src: io::handle,
     30 	orig: size,
     31 	remain: size,
     32 };
     33 
     34 // A tar file entry. Note that some systems create tarballs with additional
     35 // vendor-specific values for the entry type, so a default case is recommended
     36 // when switching against this.
     37 export type entry_type = enum u8 {
     38 	FILE,
     39 	HARDLINK,
     40 	SYMLINK,
     41 	CHARDEV,
     42 	BLOCKDEV,
     43 	DIRECTORY,
     44 	FIFO,
     45 };
     46 
     47 // Returned if the source file does not contain a valid ustar archive.
     48 export type invalid = !void;
     49 
     50 // Tagged union of all possible error types.
     51 export type error = !(invalid | io::error);
     52 
     53 // Converts an [[error]] to a human-friendly representation.
     54 export fn strerror(err: error) const str = {
     55 	match (err) {
     56 	case invalid =>
     57 		return "Tar file is invalid";
     58 	case let err: io::error =>
     59 		return io::strerror(err);
     60 	};
     61 };