python-magic icon indicating copy to clipboard operation
python-magic copied to clipboard

Retrieve both regular magic and MIME with minimal overhead

Open rmspeers opened this issue 6 years ago • 2 comments

This may be an issue with the underlying libmagic, but I'd like to retrieve both the MIME and regular magic string, e.g. 'ASCII text, with no line terminators' and 'text/plain', in a single call.

I'd like to do this without doing searches through the magic database twice, which I know is possible if I just keep two instances of Magic() myself, or if I let the library cache those for me.

Opening this to gather input on if such an improvement is possible from this library's perspective.

rmspeers avatar Sep 14 '18 13:09 rmspeers

This may be related to https://github.com/ahupp/python-magic/pull/81/files, although I think we could also solve that PR by just changing the elif for flags to an if statement to allow the ORing to stack.

rmspeers avatar Sep 14 '18 14:09 rmspeers

I don't think it's quite related to #81, because MAGIC_MIME is mutually exclusive with the textual description afaik. This is definitely a reasonable thing to want to do but I'm not sure how you'd do it without libmagic changes.

Are you actually hitting a bottlneck making two calls here? I measure about .5ms/call on my crappy host, which is pretty slow. But whether that's acceptable depends a lot on your workload.

ahupp avatar Sep 16 '18 21:09 ahupp

This would be a pretty substantial API change and without changing libmagic would not really be a perf win. There's probably space for a whole new API for libmagic, but until then I'll close.

ahupp avatar Aug 25 '23 18:08 ahupp