Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: third_party/WebKit/Source/devtools/scripts/utils.js

Issue 2344353004: DevTools: Build release mode using JS and Python (Closed)
Patch Set: fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/scripts/utils.js
diff --git a/third_party/WebKit/Source/devtools/scripts/utils.js b/third_party/WebKit/Source/devtools/scripts/utils.js
new file mode 100644
index 0000000000000000000000000000000000000000..c66e6a0d4c8ad7d37512ff482c1aa713bbfc8c84
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/scripts/utils.js
@@ -0,0 +1,62 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var fs = require("fs");
+var http = require("http");
+var https = require("https");
+var parseURL = require("url").parse;
+var Stream = require("stream").Transform;
+
+function fetch(url)
+{
+ return new Promise(fetchPromise);
+
+ function fetchPromise(resolve, reject)
+ {
+ var request;
+ var protocol = parseURL(url).protocol;
+ var handleResponse = getCallback.bind(null, resolve, reject);
+ if (protocol === "https:") {
+ request = https.get(url, handleResponse);
+ } else if (protocol === "http:") {
+ request = http.get(url, handleResponse);
+ } else {
+ reject(new Error(`Invalid protocol for url: ${url}`));
+ return;
+ }
+ request.on("error", err => reject(err));
+ }
+
+ function getCallback(resolve, reject, response)
+ {
+ if (response.statusCode !== 200) {
+ reject(new Error(`Request error: + ${response.statusCode}`));
+ return;
+ }
+ var body = new Stream();
+ response.on("data", chunk => body.push(chunk));
+ response.on("end", () => resolve(body.read()));
+ }
+}
+
+function atob(str)
+{
+ return new Buffer(str, "base64").toString("binary");
+}
+
+
+function isFile(path)
+{
+ try {
+ return fs.statSync(path).isFile();
+ } catch (e) {
+ return false;
+ }
+}
+
+module.exports = {
+ fetch,
+ atob,
+ isFile,
+};

Powered by Google App Engine
This is Rietveld 408576698