private string ExtractLibrary()

in aws-crt/CRT.cs [166:202]


            private string ExtractLibrary(string libraryName)
            {
                var crtAsm = Assembly.GetAssembly(typeof(CRT));
                Stream resourceStream = null;
                try
                {
                    resourceStream = crtAsm.GetManifestResourceStream("Aws.CRT." + libraryName);
                    if (resourceStream == null)
                    {
                        var resources = crtAsm.GetManifestResourceNames();
                        var resourceList = String.Join(",", resources);
                        throw new IOException($"Could not find {libraryName} in resource manifest; Resources={resourceList}");
                    }
                    string prefix = Path.GetRandomFileName();
                    var extractedLibraryPath = Path.GetTempPath() + prefix + "." + libraryName;
                    FileStream libStream = null;
                    // Open the shared lib stream, write the embedded stream to it, and it will be deleted later
                    try
                    {
                        libStream = new FileStream(extractedLibraryPath, FileMode.Create, FileAccess.Write);
                        CopyStream(resourceStream, libStream, 0);
                        return extractedLibraryPath;
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException($"Could not extract {libraryName} to {extractedLibraryPath}", ex);
                    }
                    finally
                    {
                        libStream?.Dispose();
                    }
                }
                finally
                {
                    resourceStream?.Dispose();
                }
            }