Skip to content

Commit c0dd063

Browse files
committed
feat: add offset support
1 parent 57f8523 commit c0dd063

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

bin/importProfileFromJSON.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const main = async () => {
2929
type: 'string',
3030
short: 'l',
3131
},
32+
offset: {
33+
type: 'string',
34+
short: 'o',
35+
},
3236
uid: {
3337
type: 'string',
3438
},
@@ -38,6 +42,7 @@ const main = async () => {
3842
const paramsSchema = z.object({
3943
path: z.string().nonempty(),
4044
limit: z.coerce.number().int().positive().default(10),
45+
offset: z.coerce.number().int().positive().default(0),
4146
uid: z.string().nonempty().default(randomUUID()),
4247
});
4348

@@ -52,9 +57,11 @@ const main = async () => {
5257
let filePaths = [params.path];
5358

5459
if (pathStat.isDirectory()) {
55-
filePaths = await readdir(params.path);
60+
filePaths = await readdir(params.path, 'utf-8');
5661
}
5762

63+
filePaths.sort(); // ensure consistent order for offset/limit
64+
5865
console.log('Found files:', filePaths.length);
5966

6067
console.log(
@@ -64,7 +71,7 @@ const main = async () => {
6471
);
6572

6673
for (const [index, fileName] of filePaths
67-
.slice(0, params.limit)
74+
.slice(params.offset, params.offset + params.limit)
6875
.entries()) {
6976
const filePath =
7077
params.path === fileName ? fileName : path.join(params.path, fileName);

0 commit comments

Comments
 (0)