Skip to content

Commit 95771a9

Browse files
author
“A1-4U2T1NN”
committed
chore: converted .pipe csv into manual csv parser;
1 parent 0cf5223 commit 95771a9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lesson_10/libraries/src/loaders/chigazo_graham_loader.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class ChigazoGrahamLoader implements Loader {
1111
async loadData(): Promise<MediaItem[]> {
1212
const credits = await this.loadCredits();
1313
const mediaItems = await this.loadMediaItems();
14-
14+
1515
console.log(
1616
`Loaded ${credits.length} credits and ${mediaItems.length} media items`,
1717
);
@@ -22,9 +22,14 @@ export class ChigazoGrahamLoader implements Loader {
2222
async loadMediaItems(): Promise<MediaItem[]> {
2323
// TODO: Implement this method.
2424
const mediaItems = [];
25-
const readable = fs
26-
.createReadStream('data/media_items.csv', 'utf-8')
27-
.pipe(csv());
25+
const readable = fs.readFileSync('data/media_items.csv', {
26+
encoding: 'utf-8'
27+
})
28+
.split('\n')
29+
.map((row: string): string[] => {
30+
return row.split(',');
31+
}
32+
);
2833
for await (const row of readable) {
2934
const { id, type, title, genre, year } = row;
3035
mediaItems.push(new MediaItem(id, type, title, genre, year));
@@ -38,8 +43,8 @@ export class ChigazoGrahamLoader implements Loader {
3843
.createReadStream('data/credits.csv', 'utf-8')
3944
.pipe(csv());
4045
for await (const row of readable) {
41-
const { media_item_id, role, name } = row;
42-
credits.push(new Credit(media_item_id, name, role));
46+
const { id, media_item_id, role, name } = row;
47+
credits.push(new Credit( id, media_item_id, name, role));
4348
}
4449
return credits;
4550
}

0 commit comments

Comments
 (0)