source: trip-planner-front/node_modules/@angular-devkit/schematics/tools/file-system-utility.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[6a3a178]1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.readJsonFile = exports.readFile = void 0;
11const core_1 = require("@angular-devkit/core");
12const fs_1 = require("fs");
13/**
14 * Read a file and returns its content. This supports different file encoding.
15 */
16function readFile(fileName) {
17 if (!fs_1.existsSync(fileName)) {
18 throw new core_1.FileDoesNotExistException(fileName);
19 }
20 const buffer = fs_1.readFileSync(fileName);
21 let len = buffer.length;
22 if (len >= 2 && buffer[0] === 0xfe && buffer[1] === 0xff) {
23 // Big endian UTF-16 byte order mark detected. Since big endian is not supported by node.js,
24 // flip all byte pairs and treat as little endian.
25 len &= ~1;
26 for (let i = 0; i < len; i += 2) {
27 const temp = buffer[i];
28 buffer[i] = buffer[i + 1];
29 buffer[i + 1] = temp;
30 }
31 return buffer.toString('utf16le', 2);
32 }
33 if (len >= 2 && buffer[0] === 0xff && buffer[1] === 0xfe) {
34 // Little endian UTF-16 byte order mark detected
35 return buffer.toString('utf16le', 2);
36 }
37 if (len >= 3 && buffer[0] === 0xef && buffer[1] === 0xbb && buffer[2] === 0xbf) {
38 // UTF-8 byte order mark detected
39 return buffer.toString('utf8', 3);
40 }
41 // Default is UTF-8 with no byte order mark
42 return buffer.toString('utf8');
43}
44exports.readFile = readFile;
45function readJsonFile(path) {
46 return core_1.parseJson(readFile(path), core_1.JsonParseMode.Loose);
47}
48exports.readJsonFile = readJsonFile;
Note: See TracBrowser for help on using the repository browser.