swc/crates/swc_bundler/tests/.cache/deno/5d5895ead3ff168faf1b1649a426ff55e4dab034.ts
2021-11-09 20:42:49 +09:00

26 lines
719 B
TypeScript

// Loaded from https://deno.land/x/dndb@0.2.4/src/methods/remove.js
import { matches } from '../../deps.ts';
import { ReadFileStream, WriteFileStream } from '../storage.ts';
export default async (filename, query) => {
const readStream = new ReadFileStream(filename);
const writeStream = new WriteFileStream(filename);
let removed = [];
query = query || {};
return new Promise((resolve, reject) => {
readStream.on('document', obj => {
if (!matches(query, obj))
writeStream.emit("write", obj)
else
removed.push(obj)
})
readStream.on("end", () => {
writeStream.emit("end");
})
writeStream.on("close", () => {
return resolve(removed)
})
})
}