[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-25ffb58e-49a9-4150-8a0d-a80ea3dcc0d8":3,"$faWWeczHiXdl3kt_K-P51XxnmGejzF1pXx7wMciMKSMA":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"25ffb58e-49a9-4150-8a0d-a80ea3dcc0d8","azure-storage-file-share-ts","Azure文件共享JavaScript\u002FTypeScript SDK（@azure\u002Fstorage-file-share）用于SMB文件共享操作。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-storage-file-share-ts\ndescription: Azure File Share JavaScript\u002FTypeScript SDK (@azure\u002Fstorage-file-share) for SMB file share operations.\nrisk: unknown\nsource: community\ndate_added: '2026-02-27'\n---\n\n# @azure\u002Fstorage-file-share (TypeScript\u002FJavaScript)\n\nSDK for Azure File Share operations — SMB file shares, directories, and file operations.\n\n## Installation\n\n```bash\nnpm install @azure\u002Fstorage-file-share @azure\u002Fidentity\n```\n\n**Current Version**: 12.x  \n**Node.js**: >= 18.0.0\n\n## Environment Variables\n\n```bash\nAZURE_STORAGE_ACCOUNT_NAME=\u003Caccount-name>\nAZURE_STORAGE_ACCOUNT_KEY=\u003Caccount-key>\n# OR connection string\nAZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=...\n```\n\n## Authentication\n\n### Connection String (Simplest)\n\n```typescript\nimport { ShareServiceClient } from \"@azure\u002Fstorage-file-share\";\n\nconst client = ShareServiceClient.fromConnectionString(\n  process.env.AZURE_STORAGE_CONNECTION_STRING!\n);\n```\n\n### StorageSharedKeyCredential (Node.js only)\n\n```typescript\nimport { ShareServiceClient, StorageSharedKeyCredential } from \"@azure\u002Fstorage-file-share\";\n\nconst accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME!;\nconst accountKey = process.env.AZURE_STORAGE_ACCOUNT_KEY!;\n\nconst sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);\nconst client = new ShareServiceClient(\n  `https:\u002F\u002F${accountName}.file.core.windows.net`,\n  sharedKeyCredential\n);\n```\n\n### DefaultAzureCredential\n\n```typescript\nimport { ShareServiceClient } from \"@azure\u002Fstorage-file-share\";\nimport { DefaultAzureCredential } from \"@azure\u002Fidentity\";\n\nconst accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME!;\nconst client = new ShareServiceClient(\n  `https:\u002F\u002F${accountName}.file.core.windows.net`,\n  new DefaultAzureCredential()\n);\n```\n\n### SAS Token\n\n```typescript\nimport { ShareServiceClient } from \"@azure\u002Fstorage-file-share\";\n\nconst accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME!;\nconst sasToken = process.env.AZURE_STORAGE_SAS_TOKEN!;\n\nconst client = new ShareServiceClient(\n  `https:\u002F\u002F${accountName}.file.core.windows.net${sasToken}`\n);\n```\n\n## Client Hierarchy\n\n```\nShareServiceClient (account level)\n└── ShareClient (share level)\n    └── ShareDirectoryClient (directory level)\n        └── ShareFileClient (file level)\n```\n\n## Share Operations\n\n### Create Share\n\n```typescript\nconst shareClient = client.getShareClient(\"my-share\");\nawait shareClient.create();\n\n\u002F\u002F Create with quota (in GB)\nawait shareClient.create({ quota: 100 });\n```\n\n### List Shares\n\n```typescript\nfor await (const share of client.listShares()) {\n  console.log(share.name, share.properties.quota);\n}\n\n\u002F\u002F With prefix filter\nfor await (const share of client.listShares({ prefix: \"logs-\" })) {\n  console.log(share.name);\n}\n```\n\n### Delete Share\n\n```typescript\nawait shareClient.delete();\n\n\u002F\u002F Delete if exists\nawait shareClient.deleteIfExists();\n```\n\n### Get Share Properties\n\n```typescript\nconst properties = await shareClient.getProperties();\nconsole.log(\"Quota:\", properties.quota, \"GB\");\nconsole.log(\"Last Modified:\", properties.lastModified);\n```\n\n### Set Share Quota\n\n```typescript\nawait shareClient.setQuota(200); \u002F\u002F 200 GB\n```\n\n## Directory Operations\n\n### Create Directory\n\n```typescript\nconst directoryClient = shareClient.getDirectoryClient(\"my-directory\");\nawait directoryClient.create();\n\n\u002F\u002F Create nested directory\nconst nestedDir = shareClient.getDirectoryClient(\"parent\u002Fchild\u002Fgrandchild\");\nawait nestedDir.create();\n```\n\n### List Directories and Files\n\n```typescript\nconst directoryClient = shareClient.getDirectoryClient(\"my-directory\");\n\nfor await (const item of directoryClient.listFilesAndDirectories()) {\n  if (item.kind === \"directory\") {\n    console.log(`[DIR] ${item.name}`);\n  } else {\n    console.log(`[FILE] ${item.name} (${item.properties.contentLength} bytes)`);\n  }\n}\n```\n\n### Delete Directory\n\n```typescript\nawait directoryClient.delete();\n\n\u002F\u002F Delete if exists\nawait directoryClient.deleteIfExists();\n```\n\n### Check if Directory Exists\n\n```typescript\nconst exists = await directoryClient.exists();\nif (!exists) {\n  await directoryClient.create();\n}\n```\n\n## File Operations\n\n### Upload File (Simple)\n\n```typescript\nconst fileClient = shareClient\n  .getDirectoryClient(\"my-directory\")\n  .getFileClient(\"my-file.txt\");\n\n\u002F\u002F Upload string\nconst content = \"Hello, World!\";\nawait fileClient.create(content.length);\nawait fileClient.uploadRange(content, 0, content.length);\n```\n\n### Upload File (Node.js - from local file)\n\n```typescript\nimport * as fs from \"fs\";\nimport * as path from \"path\";\n\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"uploaded.txt\");\nconst localFilePath = \"\u002Fpath\u002Fto\u002Flocal\u002Ffile.txt\";\nconst fileSize = fs.statSync(localFilePath).size;\n\nawait fileClient.create(fileSize);\nawait fileClient.uploadFile(localFilePath);\n```\n\n### Upload File (Buffer)\n\n```typescript\nconst buffer = Buffer.from(\"Hello, Azure Files!\");\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"buffer-file.txt\");\n\nawait fileClient.create(buffer.length);\nawait fileClient.uploadRange(buffer, 0, buffer.length);\n```\n\n### Upload File (Stream)\n\n```typescript\nimport * as fs from \"fs\";\n\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"streamed.txt\");\nconst readStream = fs.createReadStream(\"\u002Fpath\u002Fto\u002Flocal\u002Ffile.txt\");\nconst fileSize = fs.statSync(\"\u002Fpath\u002Fto\u002Flocal\u002Ffile.txt\").size;\n\nawait fileClient.create(fileSize);\nawait fileClient.uploadStream(readStream, fileSize, 4 * 1024 * 1024, 4); \u002F\u002F 4MB buffer, 4 concurrency\n```\n\n### Download File\n\n```typescript\nconst fileClient = shareClient\n  .getDirectoryClient(\"my-directory\")\n  .getFileClient(\"my-file.txt\");\n\nconst downloadResponse = await fileClient.download();\n\n\u002F\u002F Read as string\nconst chunks: Buffer[] = [];\nfor await (const chunk of downloadResponse.readableStreamBody!) {\n  chunks.push(Buffer.from(chunk));\n}\nconst content = Buffer.concat(chunks).toString(\"utf-8\");\n```\n\n### Download to File (Node.js)\n\n```typescript\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"my-file.txt\");\nawait fileClient.downloadToFile(\"\u002Fpath\u002Fto\u002Flocal\u002Fdestination.txt\");\n```\n\n### Download to Buffer (Node.js)\n\n```typescript\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"my-file.txt\");\nconst buffer = await fileClient.downloadToBuffer();\nconsole.log(buffer.toString());\n```\n\n### Delete File\n\n```typescript\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"my-file.txt\");\nawait fileClient.delete();\n\n\u002F\u002F Delete if exists\nawait fileClient.deleteIfExists();\n```\n\n### Copy File\n\n```typescript\nconst sourceUrl = \"https:\u002F\u002Faccount.file.core.windows.net\u002Fshare\u002Fsource.txt\";\nconst destFileClient = shareClient.rootDirectoryClient.getFileClient(\"destination.txt\");\n\n\u002F\u002F Start copy operation\nconst copyPoller = await destFileClient.startCopyFromURL(sourceUrl);\nawait copyPoller.pollUntilDone();\n```\n\n## File Properties & Metadata\n\n### Get File Properties\n\n```typescript\nconst fileClient = shareClient.rootDirectoryClient.getFileClient(\"my-file.txt\");\nconst properties = await fileClient.getProperties();\n\nconsole.log(\"Content-Length:\", properties.contentLength);\nconsole.log(\"Content-Type:\", properties.contentType);\nconsole.log(\"Last Modified:\", properties.lastModified);\nconsole.log(\"ETag:\", properties.etag);\n```\n\n### Set Metadata\n\n```typescript\nawait fileClient.setMetadata({\n  author: \"John Doe\",\n  category: \"documents\",\n});\n```\n\n### Set HTTP Headers\n\n```typescript\nawait fileClient.setHttpHeaders({\n  fileContentType: \"text\u002Fplain\",\n  fileCacheControl: \"max-age=3600\",\n  fileContentDisposition: \"attachment; filename=download.txt\",\n});\n```\n\n## Range Operations\n\n### Upload Range\n\n```typescript\nconst data = Buffer.from(\"partial content\");\nawait fileClient.uploadRange(data, 100, data.length); \u002F\u002F Write at offset 100\n```\n\n### Download Range\n\n```typescript\nconst downloadResponse = await fileClient.download(100, 50); \u002F\u002F offset 100, length 50\n```\n\n### Clear Range\n\n```typescript\nawait fileClient.clearRange(0, 100); \u002F\u002F Clear first 100 bytes\n```\n\n## Snapshot Operations\n\n### Create Snapshot\n\n```typescript\nconst snapshotResponse = await shareClient.createSnapshot();\nconsole.log(\"Snapshot:\", snapshotResponse.snapshot);\n```\n\n### Access Snapshot\n\n```typescript\nconst snapshotShareClient = shareClient.withSnapshot(snapshotResponse.snapshot!);\nconst snapshotFileClient = snapshotShareClient.rootDirectoryClient.getFileClient(\"file.txt\");\nconst content = await snapshotFileClient.downloadToBuffer();\n```\n\n### Delete Snapshot\n\n```typescript\nawait shareClient.delete({ deleteSnapshots: \"include\" });\n```\n\n## SAS Token Generation (Node.js only)\n\n### Generate File SAS\n\n```typescript\nimport {\n  generateFileSASQueryParameters,\n  FileSASPermissions,\n  StorageSharedKeyCredential,\n} from \"@azure\u002Fstorage-file-share\";\n\nconst sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);\n\nconst sasToken = generateFileSASQueryParameters(\n  {\n    shareName: \"my-share\",\n    filePath: \"my-directory\u002Fmy-file.txt\",\n    permissions: FileSASPermissions.parse(\"r\"), \u002F\u002F read only\n    expiresOn: new Date(Date.now() + 3600 * 1000), \u002F\u002F 1 hour\n  },\n  sharedKeyCredential\n).toString();\n\nconst sasUrl = `https:\u002F\u002F${accountName}.file.core.windows.net\u002Fmy-share\u002Fmy-directory\u002Fmy-file.txt?${sasToken}`;\n```\n\n### Generate Share SAS\n\n```typescript\nimport { ShareSASPermissions, generateFileSASQueryParameters } from \"@azure\u002Fstorage-file-share\";\n\nconst sasToken = generateFileSASQueryParameters(\n  {\n    shareName: \"my-share\",\n    permissions: ShareSASPermissions.parse(\"rcwdl\"), \u002F\u002F read, create, write, delete, list\n    expiresOn: new Date(Date.now() + 24 * 3600 * 1000), \u002F\u002F 24 hours\n  },\n  sharedKeyCredential\n).toString();\n```\n\n## Error Handling\n\n```typescript\nimport { RestError } from \"@azure\u002Fstorage-file-share\";\n\ntry {\n  await shareClient.create();\n} catch (error) {\n  if (error instanceof RestError) {\n    switch (error.statusCode) {\n      case 404:\n        console.log(\"Share not found\");\n        break;\n      case 409:\n        console.log(\"Share already exists\");\n        break;\n      case 403:\n        console.log(\"Access denied\");\n        break;\n      default:\n        console.error(`Storage error ${error.statusCode}: ${error.message}`);\n    }\n  }\n  throw error;\n}\n```\n\n## TypeScript Types Reference\n\n```typescript\nimport {\n  \u002F\u002F Clients\n  ShareServiceClient,\n  ShareClient,\n  ShareDirectoryClient,\n  ShareFileClient,\n\n  \u002F\u002F Authentication\n  StorageSharedKeyCredential,\n  AnonymousCredential,\n\n  \u002F\u002F SAS\n  FileSASPermissions,\n  ShareSASPermissions,\n  AccountSASPermissions,\n  AccountSASServices,\n  AccountSASResourceTypes,\n  generateFileSASQueryParameters,\n  generateAccountSASQueryParameters,\n\n  \u002F\u002F Options & Responses\n  ShareCreateResponse,\n  FileDownloadResponseModel,\n  DirectoryItem,\n  FileItem,\n  ShareProperties,\n  FileProperties,\n\n  \u002F\u002F Errors\n  RestError,\n} from \"@azure\u002Fstorage-file-share\";\n```\n\n## Best Practices\n\n1. **Use connection strings for simplicity** — Easiest setup for development\n2. **Use DefaultAzureCredential for production** — Enable managed identity in Azure\n3. **Set quotas on shares** — Prevent unexpected storage costs\n4. **Use streaming for large files** — `uploadStream`\u002F`downloadToFile` for files > 256MB\n5. **Use ranges for partial updates** — More efficient than full file replacement\n6. **Create snapshots before major changes** — Point-in-time recovery\n7. **Handle errors gracefully** — Check `RestError.statusCode` for specific handling\n8. **Use `*IfExists` methods** — For idempotent operations\n\n## Platform Differences\n\n| Feature | Node.js | Browser |\n|---------|---------|---------|\n| `StorageSharedKeyCredential` | ✅ | ❌ |\n| `uploadFile()` | ✅ | ❌ |\n| `uploadStream()` | ✅ | ❌ |\n| `downloadToFile()` | ✅ | ❌ |\n| `downloadToBuffer()` | ✅ | ❌ |\n| SAS generation | ✅ | ❌ |\n| DefaultAzureCredential | ✅ | ❌ |\n| Anonymous\u002FSAS access | ✅ | ✅ |\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,74,143,"2026-05-16 13:07:56",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"24340d26-fa56-463e-822a-091a07a7b77c","1.0.0","azure-storage-file-share-ts.zip",3631,"uploads\u002Fskills\u002F25ffb58e-49a9-4150-8a0d-a80ea3dcc0d8\u002Fazure-storage-file-share-ts.zip","a83a39440275ee64230cd32d552d1b8b4b95c81e5a7b03792ab7bff8585ba48e","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":12332}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]