forked from floraachy/ImageKnife
!28 1.更新FileUtils, readFilePic没有closeSync文件可能造成内存泄漏问题
Merge pull request !28 from zhoulisheng1/master
This commit is contained in:
commit
19f210ba6b
|
@ -111,18 +111,10 @@ export class FileUtils {
|
|||
*/
|
||||
writeData(path: string, content: ArrayBuffer | string) {
|
||||
try {
|
||||
console.info("FileUtils - writeData size 1= " + path)
|
||||
let fd = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE).fd
|
||||
console.info("FileUtils - writeData size 2= ")
|
||||
let stat = fs.statSync(path)
|
||||
console.info("FileUtils - writeData size = " + stat.size)
|
||||
console.info("FileUtils - writeData size = " + stat.size +" path="+path);
|
||||
fs.writeSync(fd, content, { offset: stat.size })
|
||||
let length = 0
|
||||
if (content instanceof ArrayBuffer) {
|
||||
length = content.byteLength
|
||||
} else {
|
||||
length = content.length
|
||||
}
|
||||
fs.closeSync(fd)
|
||||
} catch (e) {
|
||||
console.log("FileUtils - Failed to writeData for " + e)
|
||||
|
@ -172,13 +164,11 @@ export class FileUtils {
|
|||
readFilePic(path: string): ArrayBuffer {
|
||||
try {
|
||||
let stat = fs.statSync(path)
|
||||
console.info("FileUtils - readFilePic 1")
|
||||
let fd = fs.openSync(path, fs.OpenMode.READ_WRITE).fd;
|
||||
let length = fs.statSync(path).size
|
||||
console.info("FileUtils - readFilePic 2 length = " + length)
|
||||
let length = stat.size
|
||||
let buf = new ArrayBuffer(length);
|
||||
console.info("FileUtils - readFilePic 3")
|
||||
fs.readSync(fd, buf)
|
||||
fs.closeSync(fd)
|
||||
return buf
|
||||
} catch (e) {
|
||||
console.log("FileUtils - readFilePic " + e)
|
||||
|
|
Loading…
Reference in New Issue