Skip to content

stor needs to pass 'rb' flag to dxpy #108

@ying-w

Description

@ying-w

Currently on python3 if you're trying to stor.open() a file a DNAnexus, it will give a unicode error if you're opening a non-text (binary file).

Recently a PR was merged that adds an 'rb' mode for dxpy. Thus read_object() function in dx.py needs to be updated to reflect this.

For example, given a .png file that you want to view within jupyter notebook with DNAnexus id: project-abc:file-xyz

import stor
import dxpy
from PIL import Image

img = stor.Path('dx://project-abc:file-xyz')
with stor.open(img, "rb") as f:
    display(Image.open(io.BytesIO(f.read()))) # this will give UnicodeDecodeError

with dxpy.DXFile(dxid='file-xyz', project='project-abc', mode='rb') as dp:
    display(Image.open(io.BytesIO(dp.read()))) # this will work

dxpy.__version__ # '0.277.0+g18cd5634'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions