Begin zyb/extract
This commit is contained in:
parent
750c0ba783
commit
70c0620cfe
8 changed files with 220 additions and 9 deletions
28
include/zyb/extract.h
Normal file
28
include/zyb/extract.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef ZYB_EXTRACT_H
|
||||
#define ZYB_EXTRACT_H
|
||||
|
||||
// libc
|
||||
#include <stdio.h>
|
||||
|
||||
// libzyb
|
||||
#include <zyb/header.h>
|
||||
|
||||
// Extract leader from an open zyb
|
||||
int zyb_extract_leader(FILE *fptr, struct lead *leader);
|
||||
|
||||
// Extract (next) dependency from an open zyb
|
||||
int zyb_extract_dependency(FILE *fptr, struct dependency *dep);
|
||||
|
||||
// Extract full header from an open zyb
|
||||
int zyb_extract_header(FILE *fptr, struct zyb_header *header);
|
||||
|
||||
// Extract (next) file from an open zyb
|
||||
int zyb_extract_file(FILE *fptr, char *dir);
|
||||
|
||||
// Extract full zyb archive
|
||||
int zyb_extract_FILE(FILE *fptr, char *dir);
|
||||
|
||||
// Extract full zyb archive at `file`
|
||||
int zyb_extract(char *file, char *dir);
|
||||
|
||||
#endif
|
58
include/zyb/header.h
Normal file
58
include/zyb/header.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
#ifndef ZYB_HEADERS_H
|
||||
#define ZYB_HEADERS_H
|
||||
|
||||
// libc
|
||||
#include <sys/types.h>
|
||||
|
||||
#define ZYB_MAGIC "ZYB\0"
|
||||
#define ZYB_DEP_MAGIC "DEP\0"
|
||||
#define ZYB_FILE_MAGIC "ZIP\0"
|
||||
#define ZYB_FORMAT_VER 1
|
||||
#define ZYB_NAME_LENGTH 100
|
||||
|
||||
/*
|
||||
* This struct is the very first thing in any .zyb file.
|
||||
* It contains package metadata, such as the name and dependencies.
|
||||
*/
|
||||
struct __attribute__((__packed__, aligned(2))) zyb_header {
|
||||
/*
|
||||
* This struct is the first part of the header,
|
||||
* containing critical information about the package.
|
||||
*/
|
||||
struct __attribute__((__packed__, aligned(2))) lead {
|
||||
char magic[4]; // Magic (ZYB_MAGIC)
|
||||
unsigned short version; // Format version (ZYB_FORMAT_VER)
|
||||
char arch[6]; // Magic identifying arch
|
||||
char os[6]; // Magic identifying os
|
||||
char name[ZYB_NAME_LENGTH]; // Name of the package
|
||||
unsigned short major, minor, patch; // SemVer
|
||||
unsigned short dependencies; // Number of dependencies
|
||||
unsigned char reserved[2]; // Padding
|
||||
} leader;
|
||||
/*
|
||||
* This struct contains information about each dependency.
|
||||
* The number of these struct should EXACTLY be lead.dependencies.
|
||||
*/
|
||||
struct __attribute__((__packed__, aligned(2))) dependency {
|
||||
char magic[4]; // Magic (ZYB_DEP_MAGIC)
|
||||
char name[ZYB_NAME_LENGTH]; // Name of the dependency
|
||||
unsigned short major, minor, patch; // Minimum SemVer
|
||||
unsigned char reserved[2]; // Padding
|
||||
} dependencies[0];
|
||||
};
|
||||
|
||||
/*
|
||||
* This struct appends every single file in the .zyb.
|
||||
* It contains metadata for the individual files in the package.
|
||||
* WARNING: CHECKSUM IS FOR THE UNZIPPED FILE.
|
||||
*/
|
||||
struct __attribute__((__packed__, aligned(2))) zyb_file_header {
|
||||
char magic[4]; // Magic (ZYB_FILE_MAGIC)
|
||||
char *path; // Destination path of the file
|
||||
mode_t permissions; // UNIX permission attributes (32 bits)
|
||||
off_t length; // File length (64 bits)
|
||||
unsigned char checksum[32]; // Checksum of the unzipped file
|
||||
unsigned char reserved[2]; // Padding
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue