git/csum-file.h

#ifndef CSUM_FILE_H
#define CSUM_FILE_H

#include "hash.h"
#include "write-or-die.h"

struct progress;

/* A SHA1-protected file */
struct hashfile {};

/* Checkpoint */
struct hashfile_checkpoint {};

void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);
int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);

/* finalize_hashfile flags */
#define CSUM_CLOSE
#define CSUM_FSYNC
#define CSUM_HASH_IN_STREAM

struct hashfile *hashfd(int fd, const char *name);
struct hashfile *hashfd_check(const char *name);
struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);

/*
 * Free the hashfile without flushing its contents to disk. This only
 * needs to be called when not calling `finalize_hashfile()`.
 */
void free_hashfile(struct hashfile *f);

/*
 * Finalize the hashfile by flushing data to disk and free'ing it.
 */
int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int);
void discard_hashfile(struct hashfile *);
void hashwrite(struct hashfile *, const void *, unsigned int);
void hashflush(struct hashfile *f);
void crc32_begin(struct hashfile *);
uint32_t crc32_end(struct hashfile *);

/* Verify checksum validity while reading. Returns non-zero on success. */
int hashfile_checksum_valid(const unsigned char *data, size_t len);

/*
 * Returns the total number of bytes fed to the hashfile so far (including ones
 * that have not been written out to the descriptor yet).
 */
static inline off_t hashfile_total(struct hashfile *f)
{}

static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
{}

static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
{}

static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data)
{}

#endif