-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8c9725
commit 5b1b629
Showing
11 changed files
with
104 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
///<reference path="../lib.deno.d.ts" /> | ||
|
||
import { fstat } from "fs"; | ||
import { promisify } from "util"; | ||
|
||
import { positions } from "./seekSync.js"; | ||
|
||
const nodeFstat = promisify(fstat); | ||
|
||
export const seek: typeof Deno.seek = async function (fd, offset, whence) { | ||
let p = positions.get(fd); | ||
if (p == null) { | ||
throw new Error("Bad file descriptor"); | ||
} | ||
switch (whence) { | ||
case Deno.SeekMode.Start: | ||
p = Number(offset); | ||
break; | ||
case Deno.SeekMode.Current: | ||
p += Number(offset); | ||
break; | ||
case Deno.SeekMode.End: | ||
p = (await nodeFstat(fd)).size + Number(offset); | ||
break; | ||
default: | ||
throw new TypeError(`Invalid seek mode: ${whence}`); | ||
} | ||
positions.set(fd, p!); | ||
return p!; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
///<reference path="../lib.deno.d.ts" /> | ||
|
||
import { fstatSync } from "fs"; | ||
|
||
export const positions = new Map<number, number>(); | ||
|
||
export const seekSync: typeof Deno.seekSync = function (fd, offset, whence) { | ||
let p = positions.get(fd); | ||
if (p == null) { | ||
throw new Error("Bad file descriptor"); | ||
} | ||
switch (whence) { | ||
case Deno.SeekMode.Start: | ||
p = Number(offset); | ||
break; | ||
case Deno.SeekMode.Current: | ||
p += Number(offset); | ||
break; | ||
case Deno.SeekMode.End: | ||
p = fstatSync(fd).size + Number(offset); | ||
break; | ||
default: | ||
throw new TypeError(`Invalid seek mode: ${whence}`); | ||
} | ||
positions.set(fd, p!); | ||
return p!; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters