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

Commit db14a12

Browse files
Allow larger than 2GB files to be read.
mendsley/bsdiff#24
1 parent 8ebd8ed commit db14a12

9 files changed

Lines changed: 187 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bsdiff-nodejs",
33
"description": "An binary diff and patch library based on bsdiff algorithm for NodeJS (Windows, Mac, Linux).",
4-
"version": "2.0.8",
4+
"version": "2.1.0",
55
"repository": {
66
"type": "git",
77
"url": "git+https://github.com/Exoway/bsdiff-nodejs.git"

src/DiffWorkerCallback.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
** MIT License
3+
**
4+
** Copyright (c) 2018-2019 Exoway
5+
**
6+
** Permission is hereby granted, free of charge, to any person obtaining a copy
7+
** of this software and associated documentation files (the "Software"), to deal
8+
** in the Software without restriction, including without limitation the rights
9+
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
** copies of the Software, and to permit persons to whom the Software is
11+
** furnished to do so, subject to the following conditions:
12+
**
13+
** The above copyright notice and this permission notice shall be included in all
14+
** copies or substantial portions of the Software.
15+
**
16+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
** SOFTWARE.
23+
**
24+
*/
125

226
#include "DiffWorkerCallback.hpp"
327

src/DiffWorkerCallback.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/*
2+
** MIT License
3+
**
4+
** Copyright (c) 2018-2019 Exoway
5+
**
6+
** Permission is hereby granted, free of charge, to any person obtaining a copy
7+
** of this software and associated documentation files (the "Software"), to deal
8+
** in the Software without restriction, including without limitation the rights
9+
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
** copies of the Software, and to permit persons to whom the Software is
11+
** furnished to do so, subject to the following conditions:
12+
**
13+
** The above copyright notice and this permission notice shall be included in all
14+
** copies or substantial portions of the Software.
15+
**
16+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
** SOFTWARE.
23+
**
24+
*/
25+
126
#ifndef DiffWorkerCallback_H
227
#define DiffWorkerCallback_H
328

src/Main.cpp

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

src/PatchWorkerCallback.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
** MIT License
3+
**
4+
** Copyright (c) 2018-2019 Exoway
5+
**
6+
** Permission is hereby granted, free of charge, to any person obtaining a copy
7+
** of this software and associated documentation files (the "Software"), to deal
8+
** in the Software without restriction, including without limitation the rights
9+
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
** copies of the Software, and to permit persons to whom the Software is
11+
** furnished to do so, subject to the following conditions:
12+
**
13+
** The above copyright notice and this permission notice shall be included in all
14+
** copies or substantial portions of the Software.
15+
**
16+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
** SOFTWARE.
23+
**
24+
*/
125

226
#include "PatchWorkerCallback.hpp"
327

src/PatchWorkerCallback.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/*
2+
** MIT License
3+
**
4+
** Copyright (c) 2018-2019 Exoway
5+
**
6+
** Permission is hereby granted, free of charge, to any person obtaining a copy
7+
** of this software and associated documentation files (the "Software"), to deal
8+
** in the Software without restriction, including without limitation the rights
9+
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
** copies of the Software, and to permit persons to whom the Software is
11+
** furnished to do so, subject to the following conditions:
12+
**
13+
** The above copyright notice and this permission notice shall be included in all
14+
** copies or substantial portions of the Software.
15+
**
16+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
** SOFTWARE.
23+
**
24+
*/
25+
126
#ifndef PatchWorkerCallback_H
227
#define PatchWorkerCallback_H
328

src/c/bsdiff/bsdiff.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,25 @@ static void offtout(off_t x,u_char *buf)
233233
buf[7]|= 0x80;
234234
}
235235

236+
static off_t readFileToBuffer(int fd, uint8_t* buffer, off_t bufferSize)
237+
{
238+
off_t bytesRead = 0;
239+
int ret;
240+
while (bytesRead < bufferSize)
241+
{
242+
ret = read(fd, buffer + bytesRead, bufferSize - bytesRead);
243+
if (ret > 0)
244+
{
245+
bytesRead += ret;
246+
}
247+
else
248+
{
249+
break;
250+
}
251+
}
252+
return bytesRead;
253+
}
254+
236255
int bsdiff(const char* error, const char* oldfile, const char* newfile, const char* patchfile, void* progressWorker, void(*callback)(off_t, off_t, void*))
237256
{
238257
int fd;
@@ -259,7 +278,7 @@ int bsdiff(const char* error, const char* oldfile, const char* newfile, const ch
259278
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
260279
((old=malloc(oldsize+1))==NULL) ||
261280
(lseek(fd,0,SEEK_SET)!=0) ||
262-
(read(fd,old,oldsize)!=oldsize) ||
281+
(readFileToBuffer(fd,old,oldsize)!=oldsize) ||
263282
(close(fd)==-1))
264283
{
265284
sprintf((char*)error, "\"%s\" %s", oldfile, strerror(errno));
@@ -283,7 +302,7 @@ int bsdiff(const char* error, const char* oldfile, const char* newfile, const ch
283302
((newsize=lseek(fd,0,SEEK_END))==-1) ||
284303
((new=malloc(newsize+1))==NULL) ||
285304
(lseek(fd,0,SEEK_SET)!=0) ||
286-
(read(fd,new,newsize)!=newsize) ||
305+
(readFileToBuffer(fd,new,newsize)!=newsize) ||
287306
(close(fd)==-1))
288307
{
289308
sprintf((char*)error, "\"%s\" %s", newfile, strerror(errno));

src/c/bspatch/bspatch.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,44 @@ static off_t offtin(u_char *buf)
4646
return y;
4747
}
4848

49+
static off_t readFileToBuffer(int fd, uint8_t* buffer, off_t bufferSize)
50+
{
51+
off_t bytesRead = 0;
52+
int ret;
53+
while (bytesRead < bufferSize)
54+
{
55+
ret = read(fd, buffer + bytesRead, bufferSize - bytesRead);
56+
if (ret > 0)
57+
{
58+
bytesRead += ret;
59+
}
60+
else
61+
{
62+
break;
63+
}
64+
}
65+
return bytesRead;
66+
}
67+
68+
static off_t writeFileFromBuffer(int fd, uint8_t* buffer, off_t bufferSize)
69+
{
70+
off_t bytesWritten = 0;
71+
int ret;
72+
while (bytesWritten < bufferSize)
73+
{
74+
ret = write(fd, buffer + bytesWritten, bufferSize - bytesWritten);
75+
if (ret > 0)
76+
{
77+
bytesWritten += ret;
78+
}
79+
else
80+
{
81+
break;
82+
}
83+
}
84+
return bytesWritten;
85+
}
86+
4987
int bspatch(const char* error, const char* oldfile, const char* newfile, const char* patchfile, void* progressWorker, void(*callback)(off_t, off_t, void*))
5088
{
5189
FILE * f, * cpf, * dpf, * epf;
@@ -160,7 +198,7 @@ int bspatch(const char* error, const char* oldfile, const char* newfile, const c
160198
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
161199
((old=malloc(oldsize+1))==NULL) ||
162200
(lseek(fd,0,SEEK_SET)!=0) ||
163-
(read(fd,old,oldsize)!=oldsize) ||
201+
(readFileToBuffer(fd,old,oldsize)!=oldsize) ||
164202
(close(fd)==-1)) {
165203
sprintf((char*)error, "\"%s\" %s", oldfile, strerror(errno));
166204
return -1;
@@ -243,7 +281,8 @@ int bspatch(const char* error, const char* oldfile, const char* newfile, const c
243281
}
244282

245283
/* Write the new file */
246-
if(((fd=open(newfile,OPEN_FLAGS_CREATE,0666))<0) || (write(fd,new,header.newsize)!=header.newsize) || (close(fd)==-1))
284+
if(((fd=open(newfile,OPEN_FLAGS_CREATE,0666))<0) ||
285+
(writeFileFromBuffer(fd,new,header.newsize)!=header.newsize) || (close(fd)==-1))
247286
{
248287
sprintf((char*)error, "\"%s\" %s", newfile, strerror(errno));
249288
return -1;

src/c/shared.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
** MIT License
33
**
4-
** Copyright (c) 2018 Dezeiraud
4+
** Copyright (c) 2018-2019 Exoway
55
**
66
** Permission is hereby granted, free of charge, to any person obtaining a copy
77
** of this software and associated documentation files (the "Software"), to deal
@@ -21,7 +21,6 @@
2121
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
** SOFTWARE.
2323
**
24-
** last modified by pribault at 07/10/2018
2524
*/
2625

2726
#ifndef SHARED_H

0 commit comments

Comments
 (0)