Skip to content

Forwards information about what data block is being written to writed… #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bsdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ static void offtout(int64_t x,uint8_t *buf)
if(x<0) buf[7]|=0x80;
}

static int64_t writedata(struct bsdiff_stream* stream, const void* buffer, int64_t length)
static int64_t writedata(struct bsdiff_stream* stream, const void* buffer, int64_t length, int type)
{
int64_t result = 0;

while (length > 0)
{
const int smallsize = (int)MIN(length, INT_MAX);
const int writeresult = stream->write(stream, buffer, smallsize);
const int writeresult = stream->write(stream, buffer, smallsize, type);
if (writeresult == -1)
{
return -1;
Expand Down Expand Up @@ -294,7 +294,7 @@ static int bsdiff_internal(const struct bsdiff_request req)
lenb-=lens;
};

ctrlnext[0]=lenf;
ctrlnext[0]=lenf;
ctrlnext[1]=(scan-lenb)-(lastscan+lenf);
ctrlnext[2]=(pos-lenb)-(lastpos+lenf);

Expand All @@ -305,7 +305,7 @@ static int bsdiff_internal(const struct bsdiff_request req)
offtout(ctrlcur[2],buf+16);

/* Write control data */
if (writedata(req.stream, buf, sizeof(buf)))
if (writedata(req.stream, buf, sizeof(buf), BSDIFF_WRITECONTROL))
return -1;
};
ctrlcur[0]=ctrlnext[0];
Expand All @@ -319,13 +319,13 @@ static int bsdiff_internal(const struct bsdiff_request req)
/* Write diff data */
for(i=0;i<lenf;i++)
buffer[i]=req.new[lastscan+i]-req.old[lastpos+i];
if (writedata(req.stream, buffer, lenf))
if (writedata(req.stream, buffer, lenf, BSDIFF_WRITEDIFF))
return -1;

/* Write extra data */
for(i=0;i<(scan-lenb)-(lastscan+lenf);i++)
buffer[i]=req.new[lastscan+lenf+i];
if (writedata(req.stream, buffer, (scan-lenb)-(lastscan+lenf)))
if (writedata(req.stream, buffer, (scan-lenb)-(lastscan+lenf), BSDIFF_WRITEEXTRA))
return -1;

lastscan=scan-lenb;
Expand Down Expand Up @@ -386,7 +386,7 @@ int bsdiff(const uint8_t* source, int64_t sourcesize, const uint8_t* target, int
#include <stdlib.h>
#include <unistd.h>

static int bz2_write(struct bsdiff_stream* stream, const void* buffer, int size)
static int bz2_write(struct bsdiff_stream* stream, const void* buffer, int size, int type __attribute__((__unused__)))
{
int bz2err;
BZFILE* bz2;
Expand Down
6 changes: 5 additions & 1 deletion bsdiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@
extern "C" {
#endif

#define BSDIFF_WRITECONTROL 0
#define BSDIFF_WRITEDIFF 1
#define BSDIFF_WRITEEXTRA 2

struct bsdiff_stream
{
void* opaque;

void* (*malloc)(size_t size);
void (*free)(void* ptr);
int (*write)(struct bsdiff_stream* stream, const void* buffer, int size);
int (*write)(struct bsdiff_stream* stream, const void* buffer, int size, int type);
};

int bsdiff(const uint8_t* source, int64_t sourcesize, const uint8_t* target, int64_t targetsize, struct bsdiff_stream* stream);
Expand Down