You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to parse a json with the following format:
{
"name": "data #1",
"description": "description of data #1",
"files": [
{
"filename": "file1",
"content": "long string base 64 encoded 1"
},
{
"filename": "file2",
"content": "long string base 64 encoded 2"
}
]
}
where as output I'd like to retain the content as a stream since it can be very long, so the output structure should be something like so that afterwards I can pipe them into an S3 upload (@aws-sdk/lib-storage):
constfilesData={"file1": contentStream}];
Getting the attributes that are not "files" is easy and I omitted that from the following code, where I'm trying to get the filename as a string on one pipeline and the contents as a stream on the other one. The problem is how to connect them both?
I am thinking of doing something with two promises so that one promise is the filename and the other one is the contents stream and once both are fulfilled I would know that one file has been parsed but I'm not sure that's the best way since I will need a pair of promises for each files entry.
Is there an alternative? Thanks in advance!
constprocessFilesData=(pipeline: Readable)=>{constfilesPipeline=chain([pipeline,parser(),pick({filter: /^files\.\d+/}),]);constfilesData={};constfileNamesPipeline=chain([filesPipeline,pick({filter: "filename"}),streamValues(),({ key, value })=>{// placeholder for content using filenamefilesData[value]=null;},]);constfilesDataPipeline=chain([filesPipeline,pick({filter: "content"}),// how to identify the file here so that we can assign the stream to it?// also, this pipeline could be processed before the filename one]);// Once everything is finished, return filesData somehow};
This discussion was converted from issue #150 on May 06, 2024 03:07.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to parse a json with the following format:
where as output I'd like to retain the content as a stream since it can be very long, so the output structure should be something like so that afterwards I can pipe them into an S3 upload (@aws-sdk/lib-storage):
Getting the attributes that are not "files" is easy and I omitted that from the following code, where I'm trying to get the filename as a string on one pipeline and the contents as a stream on the other one. The problem is how to connect them both?
I am thinking of doing something with two promises so that one promise is the filename and the other one is the contents stream and once both are fulfilled I would know that one file has been parsed but I'm not sure that's the best way since I will need a pair of promises for each files entry.
Is there an alternative? Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions