How to load "file like object", instead of filename, with kivy SoundLoader? - mongodb

I need to play a mp3 file from gridfs in mongodb. I will get a file-like object instead filename (to the system disk).
I cannot find anyway to use SoundLoader to play the file like object directly. I checked the code here https://kivy.org/docs/_modules/kivy/core/audio.html. it seems that kivy audio does not suppot it. Am I right? I mean, like wave module, you can open it with file like object. I prefer not to use wave because it may has issues in different OSs.
wave.open(file[, mode])
If file is a string, open the file by that
name, otherwise treat it as a seekable file-like object.
Any other way to load the data to SouldLoader instead of filename? Many thanks.

This may not be a direct answer but could be an alternative for now. I can use GridFSBucket in GridFS to download the file in stream then save temp file to disk. Finally load by SoundLoader. With this way, it would solve the problem with large media file issue. This solution also works for image or video but require some disk storage of course.

Related

keep/copy XMP with libexif

I try to add a thumbnail to a JPEG picture using libexif.
For now I'm borrowing the code from exif (the command line tool that is shipped by the libexif team).
However I noticed the XMP tags get deleted from the metadata. There is an old bugreport here.
I tried to see how to achieve this anyway with libexif but I don't really understand how to get the XMP from input file and put it in the output file. I just want to copy all XMP data, I don't need to extract anything of it.
I saw there is a TAG EXIF_TAG_XML_PACKET in exif_tag.h but couldn't figure out how to read/write this tag.
A related solution is in this SO answer but it looks complicated. I'm not familiar coding in C.
Is it actually possible to keep all XMP when using only libexif API? Have things changed in recent years on that? How would you write this in code?
Thanks
I believe it should be somewhat straightforward. XMP fields are described in the ISO/Adobe standard. Regular Kotlin/Java/Android file I/O and some string manipulation should be all that is required.
I would start out by becoming intimately familiar with ISO 16684-1:2019. Then, write a method for your jpeg file class that grabs all the XMP fields. Store those fields in a temp file (to prevent difficult to recover data loss in the event of your code or libexif crashing). Hand the file off to libexif. Generate the thumbnail. Finally, when that's done you can restore the XMP fields. If the thumbnail is stored in an XMP field as well (and it sounds like it is), it may be easier to concatenate that field with the other ones which were already grabbed, updating the temp file so that it contains EVERY XMP field, before adding all of the XMP fields back to the jpeg.
Unfortunately, I do not currently have the time to read a 50 page ISO standard, synthesize the information, and then write the code to implement the solution. Here's a link to the standard at least, to get you started.
https://www.iso.org/obp/ui/#iso:std:iso:16684:-1:ed-2:v1:en

minifilter driver | tracking changes in files

What I'm trying to achieve is to intercept every write to a file and track the changes within the file. I want to track how much different the file content before and after the write.
So far in my minifilter driver I registered to IRP_MJ_WRITE callbacks and can now intercept writes to file. However I'm still not sure how can I obtain the content of the file before [preoperation] and the content after [postoperation].
The parameters that I have within the callback functions are:
PCFLT_RELATED_OBJECTS, PFLT_CALLBACK_DATA and I could not find anything related to the content of the file itself within these.
These are the operations that could change data in a file:
Modifying the file: IRP_MJ_WRITE, IRP_MJ_SET_INFORMATION ( specifically the FileEndOfFileInformation and FileValidDataLengthInformation information classes), IRP_MJ_FILE_SYSTEM_CONTROL ( specifically FSCTL_OFFLOAD_WRITE, FSCTL_WRITE_RAW_ENCRYPTED and FSCTL_SET_ZERO_DATA fsctl codes).
As for the content of the file itself that you just need to read it yourself.
If you mean the buffers as they are being written for example, check this out to find out more about the parameters of IRP_MJ_WRITE in the callback data. Esentially the buffer is at Data->Iopb->Parameters.Write.WriteBuffer/MdlAddress
Make sure you handle that memory correctly otherwise it will result a BSODs.
Good luck.

ObjectScript file create from stream

how can I create file (PDF file for example) from binary stream I have stored in global? I have stream stored in caché global and I need to create and save the file created by the stream using ObjectScript.
Thanks :)
It is not so easy. There is only one official way to create pdf in Cache, and it is ZEN reports. With ZEN reports you could create not only pdf, also possible to make html, xlsx. ZEN Reports used Apache FOP for generating it, any other ways also possible, but you should do it only by yourself.
Or maybe I misunderstood you, and you mean that your binary stream already contains PDF, and you just want to save it to some file. If so, you just have to copy your globalstream to filestream, with code like this:
set fs=##class(%Stream.FileBinary).%New()
set fs.Filename="c:\temp.pdf"
set tSC=fs.CopyFrom(yourStream)
set tSC=fs.%Save()

How can I rename file uploaded to s3 using javascript api?

'pickAndStore' method allows me to specify full path to the file, but I don't know it's extension at this point (file path has to be defined before file is uploaded, so it's not possible to provide a path with correct extension).
if I use 'pick' and then 'store' I have 2 files (because both methods uploads file to the s3). I can delete 'old' file, but it's not optimal and can be pain (take ages) with really big files.
Is there any better solution? Ideally to rename existing file.
Currently, there is no workaround for renaming file.
However, in our Javascript API v2 we are planing to add new callback function. onStart callback will be fired after user pick file but before file uploading. There could be option like renaming file based on original filename.
We will keep you updated.

How to preserve XMP metadata in Objective C?

I need my photo-editor app to preserve unknown metadata entries that were existing in the original photo that was opened by my app (for example, non-standard XMP meta-data)
I tried to use the Apple's built-in meta-data read/write meta-data, with no success.
Is there a way to just copy all existing meta-data to a buffer, write it as-is and then change only specific entries?
Yes.
Use Adobe XMP SDK.
Read the metadata from the image when you open it using:
SXMPFiles myFile;
ok = myFile.OpenFile(filename, kXMP_UnknownFile, opts);
myFile.GetXMP(_meta); // _meta is a data member of the class that represents your photo (probably a subclass of NSDocument).
When saving the image, write the image content, then write _meta to the output file using SXMPFiles.PutXMP(...), and then set specific metadata entries that you like.
See Adobe XMP programming guide for more details about reading and writing XMP metadata.