Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Angular.copy() does not work properly for generic ArrayBuffer type. #12680

Closed
ni0ki opened this issue Aug 26, 2015 · 2 comments
Closed

Angular.copy() does not work properly for generic ArrayBuffer type. #12680

ni0ki opened this issue Aug 26, 2015 · 2 comments

Comments

@ni0ki
Copy link

ni0ki commented Aug 26, 2015

When trying to copy an existing ArrayBuffer without using any specific view, angular.copy returns an empty / unusable object.

var genericArray = new ArrayBuffer(512);  // ArrayBuffer {byteLength:512}

var copyArray = angular.copy(genericArray);  // Wrong - Object{}
var subArray = genericArray.slice(0);  // Correct - ArrayBuffer{byteLength:512}

( JSFiddle to test )

I think either angular.copy should use ArrayBuffer.prototype.slice() (Polyfills are available for old browsers) or, at least, throw a warning to the user indicating that an ArrayBufferView must be used.

It can leads to misunderstanding of some "simple" pieces of code.

// Following HTTP mock will return incorrect value because of angular.copy.

$httpBackend.whenGET(/.*/).respond(
    function() {
        var zip = new JSZip();
        zip.file("nested/hello.txt", "Hello World\n");
        var archive = zip.generate({type:"arraybuffer"});

        return [200, archive, {
            'Content-Type': 'application/zip',
            'content-transfer-encoding': 'binary'
        }];
    }
); 
@Narretz
Copy link
Contributor

Narretz commented Nov 23, 2015

Since the built-in angular.x functions are specifically made with the core's need in mind, I have marked this as a feature rather than a bug.

@gkalpak
Copy link
Member

gkalpak commented Apr 7, 2016

Support for ArrayBuffer has been added with #13640.
It should work as expected on the v1.5.x branch.

@gkalpak gkalpak closed this as completed Apr 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants