Skip to content

Commit

Permalink
feat: impl mod
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Jul 30, 2024
1 parent 108fd19 commit e6dd42b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 39 deletions.
10 changes: 6 additions & 4 deletions internal/Archive.res
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ module Pack = {
}

let receiver = () => {
let b = Stream.Readable.makeOptions()
Js.log(b)
// let r = Stream.Readable.make()
Js.log("receiver")
}
}

let add: addFn = (file: Uint8Array.t, opts: packOption) => {
let meta = Impl.resolveHeadOptions(file, opts)
// Impl.resolveHeadOptions(file, opts)
Js.log("x")
// let resolvedOptions = Impl.resolveHeadOptions(file, opts)
// let r = encodeImpl(resolvedOptions)
// Js.log(r)
}

let done: doneFn = () => ()
Expand All @@ -75,7 +78,6 @@ module Pack = {
done,
}
}
include Impl
}

let pack = () => Pack.make()
45 changes: 45 additions & 0 deletions internal/Head.res
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,51 @@ type posixHead = {
prefix: u8, // fixedLength 155 offeset 345
}

// https://www.gnu.org/software/coreutils/manual/html_node/Numeric-Modes.html

// For some resaon if we use as enums but when we call lor func. It will use the
// enum index as the value.
module Mod = {
type t = private int
@inline("ts_uid")
let ts_uid = 0o4000
@inline("ts_gid")
let ts_gid = 0o2000
@inline("ts_vtx")
let ts_vtx = 0o1000
@inline("tu_read")
let tu_read = 0o0400
@inline("tu_write")
let tu_write = 0o0200
@inline("tu_exec")
let tu_exec = 0o0100
@inline("tg_read")
let tg_read = 0o0040
@inline("tg_write")
let tg_write = 0o0020
@inline("tg_exec")
let tg_exec = 0o0010
@inline("to_read")
let to_read = 0o0004
@inline("to_write")
let to_write = 0o0002
@inline("to_exec")
let to_exec = 0o0001
}

external lor: ('a, 'a) => 'a = "%orint"

let f_mod = Mod.tu_read->lor(Mod.tu_write)->lor(Mod.tg_read)->lor(Mod.to_read)

let d_mod =
Mod.tu_read
->lor(Mod.tu_write)
->lor(Mod.tu_exec)
->lor(Mod.tg_read)
->lor(Mod.tg_exec)
->lor(Mod.to_read)
->lor(Mod.to_exec)

module TypeFlag = {
type t =
| @as("0") REG_TYPE
Expand Down
33 changes: 0 additions & 33 deletions internal/Premission.res

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/gen-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function main() {
.map((file) => {
const relativePath = path.relative(rescriptOutputPath, file)
if (relativePath === 'Head.mjs') {
return `export { encode, decode } from './${relativePath}'`
return `export { encode, decode, f_mod, d_mod } from './${relativePath}'`
}
return `export * from './${relativePath}'`
})
Expand Down
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const typeFlag = {
cont_type: '7'
} as const

export const mod = {
const mod = {
ts_uid: 0o4000,
ts_gid: 0o2000,
ts_vtx: 0o1000,
Expand All @@ -29,6 +29,12 @@ export type TypeFlag = typeof typeFlag[keyof typeof typeFlag]

export type Mod = typeof mod[keyof typeof mod]

// export const f_mod = mod.

export declare const f_mod: number

export declare const d_mod: number

export interface HeadOptions {
name: string
mode: number
Expand All @@ -55,3 +61,10 @@ export interface DecodeOptions {
export declare function encode(options: HeadOptions): Uint8Array

export declare function decode(b: Uint8Array, options: DecodeOptions): Partial<HeadOptions>

export interface PackInstance {
add: (binary: Uint8Array, options: HeadOptions) => void
done: () => void
}

export declare function pack(): PackInstance

0 comments on commit e6dd42b

Please sign in to comment.