From 7af5041a0677b9f201a98d383a852c4515744fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 10 Oct 2020 15:05:19 +0200 Subject: Revert "feat(std/node/fs): adding readdir, rename, and some others (#7666)" (#7917) This reverts commit 40324ff74816a99ea061929ece1c6a4ff3078bc3. --- std/node/_fs/_fs_watch.ts | 111 ---------------------------------------------- 1 file changed, 111 deletions(-) delete mode 100644 std/node/_fs/_fs_watch.ts (limited to 'std/node/_fs/_fs_watch.ts') diff --git a/std/node/_fs/_fs_watch.ts b/std/node/_fs/_fs_watch.ts deleted file mode 100644 index a5f3bb9c1..000000000 --- a/std/node/_fs/_fs_watch.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { fromFileUrl } from "../path.ts"; -import { EventEmitter } from "../events.ts"; -import { notImplemented } from "../_utils.ts"; - -export function asyncIterableIteratorToCallback( - iterator: AsyncIterableIterator, - callback: (val: T, done?: boolean) => void, -) { - function next() { - iterator.next().then((obj) => { - if (obj.done) { - callback(obj.value, true); - return; - } - callback(obj.value); - next(); - }); - } - next(); -} - -export function asyncIterableToCallback( - iter: AsyncIterable, - callback: (val: T, done?: boolean) => void, -) { - const iterator = iter[Symbol.asyncIterator](); - function next() { - iterator.next().then((obj) => { - if (obj.done) { - callback(obj.value, true); - return; - } - callback(obj.value); - next(); - }); - } - next(); -} - -type watchOptions = { - persistent?: boolean; - recursive?: boolean; - encoding?: string; -}; - -type watchListener = (eventType: string, filename: string) => void; - -export function watch( - filename: string | URL, - options: watchOptions, - listener: watchListener, -): FSWatcher; -export function watch( - filename: string | URL, - listener: watchListener, -): FSWatcher; -export function watch( - filename: string | URL, - options: watchOptions, -): FSWatcher; -export function watch(filename: string | URL): FSWatcher; -export function watch( - filename: string | URL, - optionsOrListener?: watchOptions | watchListener, - optionsOrListener2?: watchOptions | watchListener, -) { - const listener = typeof optionsOrListener === "function" - ? optionsOrListener - : typeof optionsOrListener2 === "function" - ? optionsOrListener2 - : undefined; - const options = typeof optionsOrListener === "object" - ? optionsOrListener - : typeof optionsOrListener2 === "object" - ? optionsOrListener2 - : undefined; - filename = filename instanceof URL ? fromFileUrl(filename) : filename; - - const iterator = Deno.watchFs(filename, { - recursive: options?.recursive || false, - }); - - if (!listener) throw new Error("No callback function supplied"); - - const fsWatcher = new FSWatcher(() => { - if (iterator.return) iterator.return(); - }); - - fsWatcher.on("change", listener); - - asyncIterableIteratorToCallback(iterator, (val, done) => { - if (done) return; - fsWatcher.emit("change", val.kind, val.paths[0]); - }); - - return fsWatcher; -} - -class FSWatcher extends EventEmitter { - close: () => void; - constructor(closer: () => void) { - super(); - this.close = closer; - } - ref() { - notImplemented("FSWatcher.ref() is not implemented"); - } - unref() { - notImplemented("FSWatcher.unref() is not implemented"); - } -} -- cgit v1.2.3