Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Allow larger than 2GB files to be read.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetandezeiraud committed Sep 27, 2019
1 parent 8ebd8ed commit db14a12
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bsdiff-nodejs",
"description": "An binary diff and patch library based on bsdiff algorithm for NodeJS (Windows, Mac, Linux).",
"version": "2.0.8",
"version": "2.1.0",
"repository": {
"type": "git",
"url": "git+https://github.com/Exoway/bsdiff-nodejs.git"
Expand Down
24 changes: 24 additions & 0 deletions src/DiffWorkerCallback.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
** MIT License
**
** Copyright (c) 2018-2019 Exoway
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
**
*/

#include "DiffWorkerCallback.hpp"

Expand Down
25 changes: 25 additions & 0 deletions src/DiffWorkerCallback.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/*
** MIT License
**
** Copyright (c) 2018-2019 Exoway
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
**
*/

#ifndef DiffWorkerCallback_H
#define DiffWorkerCallback_H

Expand Down
25 changes: 25 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/*
** MIT License
**
** Copyright (c) 2018-2019 Exoway
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
**
*/

#include <node.h>
#include "DiffWorkerCallback.hpp"
#include "PatchWorkerCallback.hpp"
Expand Down
24 changes: 24 additions & 0 deletions src/PatchWorkerCallback.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
** MIT License
**
** Copyright (c) 2018-2019 Exoway
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
**
*/

#include "PatchWorkerCallback.hpp"

Expand Down
25 changes: 25 additions & 0 deletions src/PatchWorkerCallback.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/*
** MIT License
**
** Copyright (c) 2018-2019 Exoway
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
**
*/

#ifndef PatchWorkerCallback_H
#define PatchWorkerCallback_H

Expand Down
23 changes: 21 additions & 2 deletions src/c/bsdiff/bsdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ static void offtout(off_t x,u_char *buf)
buf[7]|= 0x80;
}

static off_t readFileToBuffer(int fd, uint8_t* buffer, off_t bufferSize)
{
off_t bytesRead = 0;
int ret;
while (bytesRead < bufferSize)
{
ret = read(fd, buffer + bytesRead, bufferSize - bytesRead);
if (ret > 0)
{
bytesRead += ret;
}
else
{
break;
}
}
return bytesRead;
}

int bsdiff(const char* error, const char* oldfile, const char* newfile, const char* patchfile, void* progressWorker, void(*callback)(off_t, off_t, void*))
{
int fd;
Expand All @@ -259,7 +278,7 @@ int bsdiff(const char* error, const char* oldfile, const char* newfile, const ch
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
((old=malloc(oldsize+1))==NULL) ||
(lseek(fd,0,SEEK_SET)!=0) ||
(read(fd,old,oldsize)!=oldsize) ||
(readFileToBuffer(fd,old,oldsize)!=oldsize) ||
(close(fd)==-1))
{
sprintf((char*)error, "\"%s\" %s", oldfile, strerror(errno));
Expand All @@ -283,7 +302,7 @@ int bsdiff(const char* error, const char* oldfile, const char* newfile, const ch
((newsize=lseek(fd,0,SEEK_END))==-1) ||
((new=malloc(newsize+1))==NULL) ||
(lseek(fd,0,SEEK_SET)!=0) ||
(read(fd,new,newsize)!=newsize) ||
(readFileToBuffer(fd,new,newsize)!=newsize) ||
(close(fd)==-1))
{
sprintf((char*)error, "\"%s\" %s", newfile, strerror(errno));
Expand Down
43 changes: 41 additions & 2 deletions src/c/bspatch/bspatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,44 @@ static off_t offtin(u_char *buf)
return y;
}

static off_t readFileToBuffer(int fd, uint8_t* buffer, off_t bufferSize)
{
off_t bytesRead = 0;
int ret;
while (bytesRead < bufferSize)
{
ret = read(fd, buffer + bytesRead, bufferSize - bytesRead);
if (ret > 0)
{
bytesRead += ret;
}
else
{
break;
}
}
return bytesRead;
}

static off_t writeFileFromBuffer(int fd, uint8_t* buffer, off_t bufferSize)
{
off_t bytesWritten = 0;
int ret;
while (bytesWritten < bufferSize)
{
ret = write(fd, buffer + bytesWritten, bufferSize - bytesWritten);
if (ret > 0)
{
bytesWritten += ret;
}
else
{
break;
}
}
return bytesWritten;
}

int bspatch(const char* error, const char* oldfile, const char* newfile, const char* patchfile, void* progressWorker, void(*callback)(off_t, off_t, void*))
{
FILE * f, * cpf, * dpf, * epf;
Expand Down Expand Up @@ -160,7 +198,7 @@ int bspatch(const char* error, const char* oldfile, const char* newfile, const c
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
((old=malloc(oldsize+1))==NULL) ||
(lseek(fd,0,SEEK_SET)!=0) ||
(read(fd,old,oldsize)!=oldsize) ||
(readFileToBuffer(fd,old,oldsize)!=oldsize) ||
(close(fd)==-1)) {
sprintf((char*)error, "\"%s\" %s", oldfile, strerror(errno));
return -1;
Expand Down Expand Up @@ -243,7 +281,8 @@ int bspatch(const char* error, const char* oldfile, const char* newfile, const c
}

/* Write the new file */
if(((fd=open(newfile,OPEN_FLAGS_CREATE,0666))<0) || (write(fd,new,header.newsize)!=header.newsize) || (close(fd)==-1))
if(((fd=open(newfile,OPEN_FLAGS_CREATE,0666))<0) ||
(writeFileFromBuffer(fd,new,header.newsize)!=header.newsize) || (close(fd)==-1))
{
sprintf((char*)error, "\"%s\" %s", newfile, strerror(errno));
return -1;
Expand Down
3 changes: 1 addition & 2 deletions src/c/shared.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
** MIT License
**
** Copyright (c) 2018 Dezeiraud
** Copyright (c) 2018-2019 Exoway
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,7 +21,6 @@
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
**
** last modified by pribault at 07/10/2018
*/

#ifndef SHARED_H
Expand Down

0 comments on commit db14a12

Please sign in to comment.