當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript tail.Tail類代碼示例

本文整理匯總了TypeScript中tail.Tail的典型用法代碼示例。如果您正苦於以下問題:TypeScript Tail類的具體用法?TypeScript Tail怎麽用?TypeScript Tail使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Tail類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: latestVersion

    latestVersion("mirakurun").then(latest => {

        if (!req.query.force && current === latest) {
            api.responseError(res, 409, "Update Nothing");
            return;
        }

        let command;
        const args = [
            "install",
            "mirakurun@latest",
            "-g",
            "--production"
        ];
        if (process.platform === "win32") {
            command = "npm.cmd";
        } else {
            command = "npm";
            args.push("--unsafe");
        }

        res.setHeader("Content-Type", "text/plain; charset=utf-8");
        res.status(202);
        res.write("Updating...\n");

        const path = join(tmpdir(), "Mirakurun_Updating.log");
        if (existsSync(path) === true) {
            unlinkSync(path);
        }

        const out = openSync(path, "a");
        const err = openSync(path, "a");

        res.write(`> ${command} ${args.join(" ")}\n\n`);

        const npm = spawn(command, args, {
            detached: true,
            stdio: ["ignore", out, err]
        });
        npm.unref();

        const tail = new Tail(path);
        tail.on("line", data => res.write(data + "\n"));

        req.once("close", () => {
            tail.removeAllListener("line");
            tail.unwatch();
        });
    });
開發者ID:tosono,項目名稱:Mirakurun,代碼行數:49,代碼來源:update.ts

示例2: async

export const put: Operation = async (req, res) => {

    if (!req.query.force && !process.env.pm_uptime && !process.env.USING_WINSER) {
        api.responseError(res, 500);
        return;
    }

    const latest = await latestVersion("mirakurun");

    if (!req.query.force && current === latest) {
        api.responseError(res, 409, "Update Nothing");
        return;
    }

    res.setHeader("Content-Type", "text/plain; charset=utf-8");
    res.status(202);
    res.write("Updating...\n");

    const path = join(tmpdir(), "Mirakurun_Updating.log");
    if (existsSync(path) === true) {
        unlinkSync(path);
    }

    const out = openSync(path, "a");
    const err = openSync(path, "a");

    res.write(`> node lib/updater\n\n`);

    const npm = spawn("node", ["lib/updater"], {
        detached: true,
        stdio: ["ignore", out, err]
    });
    npm.unref();

    const tail = new Tail(path);
    tail.on("line", data => res.write(data + "\n"));

    req.once("close", () => {
        tail.removeAllListeners("line");
        tail.unwatch();
    });
};
開發者ID:upsilon,項目名稱:Mirakurun,代碼行數:42,代碼來源:update.ts

示例3: watchFile

function watchFile(file:any) {
  const tail = new Tail(file);

  // Specific errors handling
  process.on('uncaughtException', (err:any) => {
    if (err.code === "ENOENT") {
      console.error('EXCEPTION: ', err.message);
      setTimeout(() => watchFile(file), 1000) // Wait a second
    }
  });

  // On new line
  tail.on("line", function(data:any) {
    console.log(data);
  });

  tail.on("error", function(error:any) {
    console.error('ERROR: ', error);
  });
}
開發者ID:duniter,項目名稱:duniter,代碼行數:20,代碼來源:daemon.ts

示例4: return

 return () => {
   let logTail = new Tail(
     tailConfig.filename,
     tailConfig.lineSeparator,
     tailConfig.watchOptions,
     tailConfig.fromStart
   );
   return new Observable(o => {
     logTail.on('line', (line) => o.next(line));
     logTail.on('err', (err) => o.error(err));
     logTail.on('end', () => o.complete());
   });
 };
開發者ID:jonesnc,項目名稱:gustav,代碼行數:13,代碼來源:helpers.ts

示例5: Tail

export const get: Operation = (req, res) => {

    if (!process.env.LOG_STDOUT || !process.env.LOG_STDERR) {
        res.writeHead(500, "Unknown Logfile Path", {
            "Content-Type": "text/plain"
        });
        res.end("Unknown Logfile Path");
        return;
    }
    if (!fs.existsSync(process.env.LOG_STDOUT) || !fs.existsSync(process.env.LOG_STDERR)) {
        res.writeHead(500, "Logfile Unavailable", {
            "Content-Type": "text/plain"
        });
        res.end("Logfile Unavailable");
        return;
    }

    res.setHeader("Content-Type", "text/plain; charset=utf-8");
    res.status(200);

    const stdout = new Tail(process.env.LOG_STDOUT);
    const stderr = new Tail(process.env.LOG_STDERR);

    req.setTimeout(1000 * 60 * 60, () => { });
    req.once("close", () => {
        stdout.removeListener("line", _listener);
        stdout.unwatch();
        stderr.removeListener("line", _listener);
        stderr.unwatch();
    });

    stdout.on("line", _listener);
    stderr.on("line", _listener);

    function _listener(data: string) {
        res.write(data + "\n");
    }
};
開發者ID:tosono,項目名稱:Mirakurun,代碼行數:38,代碼來源:stream.ts

示例6: Observable

 return new Observable(o => {
   logTail.on('line', (line) => o.next(line));
   logTail.on('err', (err) => o.error(err));
   logTail.on('end', () => o.complete());
 });
開發者ID:jonesnc,項目名稱:gustav,代碼行數:5,代碼來源:helpers.ts

示例7: Tail

import { Tail } from 'tail';

const tail = new Tail("test.txt");

tail.on("line", data => {
    console.log(data);
});

tail.on("error", error => {
    console.log('ERROR: ', error);
});

tail.unwatch();

tail.watch();

// With options object
const tail2 = new Tail("test2.txt", {
    separator: /[\r]{0,1}\n/,
    fromBeginning: false,
    fsWatchOptions: {},
    follow: true,
    logger: console,
    useWatchFile: false,
    encoding: 'utf-8'
});
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:26,代碼來源:tail-tests.ts

示例8:

 req.once("close", () => {
     tail.removeAllListener("line");
     tail.unwatch();
 });
開發者ID:tosono,項目名稱:Mirakurun,代碼行數:4,代碼來源:update.ts

示例9:

 req.once("close", () => {
     stdout.removeListener("line", _listener);
     stdout.unwatch();
     stderr.removeListener("line", _listener);
     stderr.unwatch();
 });
開發者ID:tosono,項目名稱:Mirakurun,代碼行數:6,代碼來源:stream.ts


注:本文中的tail.Tail類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。