فهرست منبع

fix(buffer): Remove new Buffer calls

Marcelo Fornet 5 سال پیش
والد
کامیت
646abb90ee
1فایلهای تغییر یافته به همراه5 افزوده شده و 20 حذف شده
  1. 5 20
      src/core.ts

+ 5 - 20
src/core.ts

@@ -1,6 +1,6 @@
 'use strict';
 'use strict';
 import * as child_process from 'child_process';
 import * as child_process from 'child_process';
-import { closeSync, copyFileSync, existsSync, mkdirSync, openSync, readdirSync, readSync, writeSync } from "fs";
+import { closeSync, copyFileSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, writeSync } from "fs";
 import { basename, dirname, extname, join } from "path";
 import { basename, dirname, extname, join } from "path";
 import * as vscode from 'vscode';
 import * as vscode from 'vscode';
 import * as gwen from './gwen';
 import * as gwen from './gwen';
@@ -352,14 +352,7 @@ export function timedRun(path: string, tcName: string, timeout: number) {
     let tcOutput = join(path, TESTCASES, `${tcName}.out`);
     let tcOutput = join(path, TESTCASES, `${tcName}.out`);
     let tcCurrent = join(path, TESTCASES, `${tcName}.real`);
     let tcCurrent = join(path, TESTCASES, `${tcName}.real`);
 
 
-    // TODO: Don't create Buffer from constructor `new Buffer()`. See warning:
-    // (node:17458) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
-
-    let inputFd = openSync(tcInput, 'r');
-    let buffer = new Buffer(getMaxSizeInput());
-    readSync(inputFd, buffer, 0, getMaxSizeInput(), 0);
-    let tcData = buffer.toString();
-    closeSync(inputFd);
+    let tcData = readFileSync(tcInput, "utf8");
 
 
     let startTime = new Date().getTime();
     let startTime = new Date().getTime();
     let command = `${join(path, ATTIC, "sol.exe")}`;
     let command = `${join(path, ATTIC, "sol.exe")}`;
@@ -417,11 +410,7 @@ export function compileCode(pathCode: string, pathOutput: string) {
     let md5data = "";
     let md5data = "";
 
 
     if (existsSync(pathCodeMD5)) {
     if (existsSync(pathCodeMD5)) {
-        let codeMD5fd = openSync(pathCodeMD5, 'r');
-        let buffer = new Buffer(getMaxSizeInput());
-        readSync(codeMD5fd, buffer, 0, 32, 0);
-        md5data = buffer.toString().slice(0, 32);
-        closeSync(codeMD5fd);
+        md5data = readFileSync(pathCodeMD5, "utf8");
     }
     }
 
 
     let codeMD5 = md5File.sync(pathCode);
     let codeMD5 = md5File.sync(pathCode);
@@ -561,14 +550,10 @@ export function stressSolution(path: string, times: number) {
         generateTestcase(path);
         generateTestcase(path);
 
 
         // Generate output testcase from brute.cpp
         // Generate output testcase from brute.cpp
-        let inputFd = openSync(join(path, TESTCASES, 'gen.in'), 'r');
-        let buffer = new Buffer(getMaxSizeInput());
-        readSync(inputFd, buffer, 0, getMaxSizeInput(), 0);
-        let tcData = buffer.toString();
-        closeSync(inputFd);
+        let tcData = readFileSync(join(path, TESTCASES, 'gen.in'), "utf8");
 
 
         // Run without restrictions
         // Run without restrictions
-        // TODO: 005
+        // TODO(#36)
         let runResult = child_process.spawnSync(brout, {
         let runResult = child_process.spawnSync(brout, {
             input: tcData,
             input: tcData,
         });
         });