< Summary

Class:DCL.GLTFast.Wrappers.GltfDownloaderWrapper
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTFast/Wrappers/GLTFDownloaderWrapper.cs
Covered lines:0
Uncovered lines:20
Coverable lines:20
Total lines:63
Line coverage:0% (0 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GltfDownloaderWrapper(...)0%2100%
IsGltfBinary(...)0%2100%
MoveNext()0%2100%
Dispose()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTFast/Wrappers/GLTFDownloaderWrapper.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using GLTFast;
 4using GLTFast.Loading;
 5using UnityEngine;
 6using UnityEngine.Networking;
 7
 8namespace DCL.GLTFast.Wrappers
 9{
 10    public class GltfDownloaderWrapper : IDownload
 11    {
 12        /// <summary>
 13        /// First four bytes of a glTF-Binary file are made up of this signature
 14        /// Represents glTF in ASCII
 15        /// </summary>
 16        private const uint GLB_SIGNATURE = 0x46546c67;
 17
 18        private readonly WebRequestAsyncOperation asyncOp;
 19        private byte[] cachedData;
 20        private bool isDisposed;
 21
 022        public GltfDownloaderWrapper(WebRequestAsyncOperation asyncOp)
 23        {
 024            this.asyncOp = asyncOp;
 025        }
 26
 027        public bool Success => asyncOp.isSucceeded;
 028        public string Error => asyncOp.webRequest.error;
 29
 30        public byte[] Data
 31        {
 32            get
 33            {
 034                if (isDisposed) return null;
 035                if (cachedData != null) return cachedData;
 36
 037                UnityWebRequest asyncOpWebRequest = asyncOp.webRequest;
 038                if (asyncOpWebRequest != null) return asyncOpWebRequest.downloadHandler.data;
 039                Debug.LogWarning("The web request was disposed?" + asyncOp.isDisposed);
 040                return null;
 41            }
 42        }
 43
 044        public string Text => asyncOp.webRequest.downloadHandler.text;
 045        public bool? IsBinary => IsGltfBinary(Data);
 46
 47        private static bool IsGltfBinary(byte[] data)
 48        {
 049            var gltfBinarySignature = BitConverter.ToUInt32(data, 0);
 050            return gltfBinarySignature == GLB_SIGNATURE;
 51        }
 52
 53        public bool MoveNext() =>
 054            asyncOp.MoveNext();
 55
 56        public void Dispose()
 57        {
 058            isDisposed = true;
 059            cachedData = null;
 060            asyncOp.Dispose();
 061        }
 62    }
 63}