// Generated using `moon info`, DON'T EDIT IT
package "Magic486/moonsquash"

import {
  "moonbitlang/core/debug",
}

// Values
pub fn build_image(Array[BuildEntry], block_size? : Int, created? : UInt, attributes? : Map[String, BuildMetadata], compression? : Int, encode? : ((Int, Bytes) -> Bytes raise SquashError)?, fragments? : Bool, exportable? : Bool, metadata_compression? : Bool) -> Bytes raise SquashError

pub fn build_to(Array[BuildEntry], (Int, Bytes) -> Unit raise SquashError, (String, Int, Int) -> Bytes raise SquashError, block_size? : Int, created? : UInt, attributes? : Map[String, BuildMetadata], compression? : Int, encode? : ((Int, Bytes) -> Bytes raise SquashError)?, fragments? : Bool, exportable? : Bool, metadata_compression? : Bool, max_data? : UInt64) -> Superblock raise SquashError

pub fn diff_images(Image, Image) -> Array[Difference] raise SquashError

pub fn no_decompressor(Int, Bytes, Int) -> Bytes raise SquashError

pub fn open_image(Bytes, decode? : (Int, Bytes, Int) -> Bytes raise SquashError) -> Image raise SquashError

pub fn open_source(Int, (Int, Int) -> Bytes raise SquashError, decode? : (Int, Bytes, Int) -> Bytes raise SquashError) -> Image raise SquashError

pub fn read_superblock(Bytes) -> Superblock raise SquashError

// Errors
pub(all) suberror SquashError {
  Invalid(Int, String)
  Unsupported(String)
  Limit(String)
} derive(@debug.Debug)

// Types and methods
pub(all) enum BuildContent {
  Folder
  Regular(Bytes)
  External(Int)
  Symbolic(Bytes)
  Hardlink(String)
  BlockDevice(UInt)
  CharDevice(UInt)
  Fifo
  Socket
} derive(@debug.Debug)

pub(all) struct BuildEntry {
  path : String
  mode : Int
  content : BuildContent
} derive(@debug.Debug)

pub(all) struct BuildMetadata {
  uid : UInt
  gid : UInt
  mtime : UInt
  xattrs : Array[Xattr]
} derive(@debug.Debug)

pub(all) enum Content {
  Directory(Int, Int, Int)
  File(Int, Int, UInt, Int, Array[UInt])
  Symlink(Bytes)
  Device(UInt)
  Special
} derive(@debug.Debug)

pub(all) struct Difference {
  path : String
  changes : Array[String]
} derive(@debug.Debug)

pub(all) struct DirEntry {
  name : Bytes
  reference : UInt64
  number : Int
  kind : Int
} derive(@debug.Debug)

pub struct Image {
  read : (Int, Int) -> Bytes raise SquashError
  superblock : Superblock
  decode : (Int, Bytes, Int) -> Bytes raise SquashError
  cache : Map[Int, (Bytes, Int)]
  data_cache : Map[String, Bytes]
  offsets : Map[UInt64, Array[Int]]
}
pub fn Image::compression_options(Self) -> Bytes? raise SquashError
pub fn Image::entries(Self, Inode) -> Array[DirEntry] raise SquashError
pub fn Image::export_inode(Self, Int) -> Inode raise SquashError
pub fn Image::header(Self) -> Superblock
pub fn Image::inode(Self, UInt64) -> Inode raise SquashError
pub fn Image::lookup(Self, String) -> Inode raise SquashError
pub fn Image::read_file(Self, Inode, max_bytes? : Int) -> Bytes raise SquashError
pub fn Image::read_range(Self, Inode, Int, Int) -> Bytes raise SquashError
pub fn Image::root(Self) -> Inode raise SquashError
pub fn Image::tree(Self, max_entries? : Int) -> Array[TreeEntry] raise SquashError
pub fn Image::verify(Self, max_bytes? : UInt64) -> VerifyReport raise SquashError
pub fn Image::xattrs(Self, Inode) -> Array[Xattr] raise SquashError

pub(all) struct Inode {
  reference : UInt64
  number : Int
  kind : Int
  mode : Int
  uid : UInt
  gid : UInt
  mtime : UInt
  links : Int
  xattr : UInt
  parent : Int
  content : Content
} derive(@debug.Debug)

pub(all) struct Superblock {
  inodes : Int
  created : UInt
  block_size : Int
  fragments : Int
  compression : Int
  flags : Int
  ids : Int
  root : UInt64
  bytes_used : Int
  inode_table : Int
  directory_table : Int
  fragment_table : Int
  id_table : Int
  xattr_table : UInt64
  export_table : UInt64
} derive(@debug.Debug)

pub(all) struct TreeEntry {
  path : String
  inode : Inode
} derive(@debug.Debug)

pub(all) struct VerifyReport {
  entries : Int
  inodes : Int
  files : Int
  bytes_checked : UInt64
  xattrs : Int
  fragments : Int
  export_checked : Bool
} derive(@debug.Debug)

pub(all) struct Xattr {
  name : Bytes
  value : Bytes
} derive(Eq, @debug.Debug)

// Type aliases

// Traits
